Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ LDAP_USER=
LDAP_PWD=

ANNAL_UPLOAD_DIR=uploads/exams/
MEDIA_UPLOAD_DIR=uploads/media
MEDIA_DETACHED_LIFESPAN=1

CAS_URL=https://cas.utt.fr/cas
CAS_SERVICE=http://localhost:8080

Expand Down
3 changes: 3 additions & 0 deletions .env.test.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ PAGINATION_PAGE_SIZE=20
FAKER_SEED=42

ANNAL_UPLOAD_DIR=uploads/exams/
MEDIA_UPLOAD_DIR=uploads/media
MEDIA_DETACHED_LIFESPAN=1

CAS_URL=https://cas.utt.fr/cas
CAS_SERVICE=https://etu.utt.fr/login
LDAP_URL=ldap://localhost:3002
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"fast-xml-parser": "^5.0.9",
"file-type": "^20.4.1",
"ldapts": "^7.3.1",
"lexical": "^0.37.0",
"multer": "1.4.5-lts.1",
"pactum-matchers": "^1.1.7",
"passport-jwt": "^4.0.1",
Expand Down
20 changes: 14 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 36 additions & 10 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ model Asso {
mail String @unique @db.VarChar(100)
phoneNumber String? @db.VarChar(30)
website String? @db.VarChar(100)
logo String? @db.VarChar(100)
logoMediaId String? @db.Char(36)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
descriptionShortTranslationId String? @unique
descriptionTranslationId String? @unique
assoAccountId String @unique // User account of the asso

logo ImageMedia? @relation("logo", fields: [logoMediaId], references: [id], onDelete: SetNull)
descriptionImages ImageMedia[] @relation("descriptionImages")
descriptionShortTranslation Translation? @relation(name: "descriptionShortTranslation", fields: [descriptionShortTranslationId], references: [id], onDelete: Cascade)
descriptionTranslation Translation? @relation(name: "descriptionTranslation", fields: [descriptionTranslationId], references: [id], onDelete: Cascade)
assoMemberships AssoMembership[]
Expand Down Expand Up @@ -162,6 +164,22 @@ model GitHubIssue {
user User @relation(fields: [userId], references: [id])
}

model ImageMedia {
id String @id @default(uuid()) @db.Char(36)
size Int @db.UnsignedInt
width Int @db.UnsignedInt
height Int @db.UnsignedInt
uploadedAt DateTime @default(now())
isPublic Boolean @default(false)
uploaderId String?
preset ImageMediaPreset

uploader User? @relation(fields: [uploaderId], references: [id])
avatarForUsers UserInfos[]
logoForAssos Asso[] @relation("logo")
descriptionForAssos Asso[] @relation("descriptionImages")
}

model Semester {
code String @id @db.Char(3)
start DateTime @db.Date
Expand Down Expand Up @@ -592,6 +610,7 @@ model User {
apiPermissionsTarget ApiKeyPermission[] @relation(name: "target")
apiPermissionsGrants ApiKeyPermission[] @relation(name: "granter")
asso Asso?
uploadedImages ImageMedia[]
}

model UserAddress {
Expand Down Expand Up @@ -662,16 +681,17 @@ model UserFormation {
}

model UserInfos {
id String @id @default(uuid())
sex Sex?
nationality String? @db.VarChar(50)
birthday DateTime? @db.Date
avatar String @default("default.png") @db.VarChar(255)
nickname String? @db.VarChar(50)
passions String? @db.Text
website String? @db.VarChar(255)
id String @id @default(uuid())
sex Sex?
nationality String? @db.VarChar(50)
birthday DateTime? @db.Date
avatarMediaId String? @db.Char(36)
nickname String? @db.VarChar(50)
passions String? @db.Text
website String? @db.VarChar(255)

user User?
user User?
avatar ImageMedia? @relation(fields: [avatarMediaId], references: [id], onDelete: SetNull)
}

model UserMailsPhones {
Expand Down Expand Up @@ -899,13 +919,19 @@ enum AddressPrivacy {
ALL_PUBLIC
}

enum ImageMediaPreset {
AVATAR
CUSTOM
}

enum Permission {
API_SEE_OPINIONS_UE // See the rates of an UE
API_GIVE_OPINIONS_UE // Rate an UE you have done or are doing
API_SEE_ANNALS // See and download annals
API_UPLOAD_ANNALS // Upload an annal
API_MODERATE_ANNALS // Moderate annals
API_MODERATE_COMMENTS // Moderate comments
API_UPLOAD_MEDIA // Upload to media enpoints

USER_SEE_DETAILS // See personal details about someone, even the ones the user decided to hide
USER_UPDATE_DETAILS // Update personal details about someone
Expand Down
53 changes: 34 additions & 19 deletions prisma/seed/modules/asso.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,40 @@ export default function assoSeed(prisma: PrismaClient) {
for (let i = 0; i < fakerRounds; i++) {
const date: Date = faker.date.past();
const name = faker.company.name();
assos.push(
prisma.asso.create({
assos.push(async () => {
const { id: userId } = await prisma.user.create({
data: {
login: name,
firstName: '',
lastName: '',
userType: UserType.ASSOCIATION,
socialNetwork: { create: {} },
mailsPhones: { create: {} },
rgpd: { create: {} },
preference: { create: {} },
infos: { create: {} },
privacy: { create: {} },
},
select: { id: true },
});
return prisma.asso.create({
data: {
name,
mail: faker.internet.email(),
phoneNumber: faker.phone.number(),
website: faker.internet.domainName(),
logo: faker.image.urlLoremFlickr({ category: 'business' }),
logo: {
create: {
height: 100,
width: 100,
size: 1024,
isPublic: true,
preset: 'AVATAR',
uploader: {
connect: { id: userId },
},
},
},
createdAt: date,
updatedAt: date,
descriptionShortTranslation: {
Expand All @@ -31,22 +57,11 @@ export default function assoSeed(prisma: PrismaClient) {
},
},
assoAccount: {
create: {
login: name,
firstName: '',
lastName: '',
userType: UserType.ASSOCIATION,
socialNetwork: { create: {} },
mailsPhones: { create: {} },
rgpd: { create: {} },
preference: { create: {} },
infos: { create: {} },
privacy: { create: {} },
}
}
connect: { id: userId },
},
},
}),
);
});
});
}
return Promise.all(assos);
return Promise.all(assos.map((assoFn) => assoFn()));
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { BranchModule } from './branch/branch.module';
import { AssosModule } from './assos/assos.module';
import { TranslationInterceptor } from './app.interceptor';
import { SemesterModule } from './semester/semester.module';
import { ImageMediaModule } from './media/image/imagemedia.module';

@Module({
imports: [
ConfigModule,
HttpModule,
PrismaModule,
ImageMediaModule,
SemesterModule,
AuthModule,
ProfileModule,
Expand Down
24 changes: 16 additions & 8 deletions src/app.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
ParseUUIDPipe,
Type,
ArgumentMetadata,
BadRequestException,
Injectable,
PipeTransform,
ValidationPipe,
ParseIntPipe,
} from '@nestjs/common';
import { AppException, ERROR_CODE } from './exceptions';
import { validationExceptionFactory } from './validation';
Expand Down Expand Up @@ -47,6 +47,18 @@ export const UUIDParam = (property: string, ...pipes: (Type<PipeTransform> | Pip
...pipes,
);

export const IntParam = (property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]) =>
Param(
property,
new ParseIntPipe({
exceptionFactory: () => new AppException(ERROR_CODE.PARAM_NOT_NUMBER, property),
}),
...pipes,
);

export const PositiveIntParam = (property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]) =>
Param(property, new PositiveNumberValidationPipe(), ...pipes);

export interface ArrayDto<T> extends Array<T> {
items: T[];
}
Expand Down Expand Up @@ -86,14 +98,10 @@ export class AppValidationPipe extends ValidationPipe {

@Injectable()
export class PositiveNumberValidationPipe implements PipeTransform {
async transform(value: string) {
async transform(value: string, metadata: ArgumentMetadata) {
const asNumber = Number.parseInt(value);
if (Number.isNaN(asNumber)) {
throw new BadRequestException('value must be a positive number');
}
if (asNumber <= 0) {
throw new BadRequestException('value must be a positive number');
}
if (Number.isNaN(asNumber)) throw new AppException(ERROR_CODE.PARAM_NOT_NUMBER, metadata.data);
if (asNumber <= 0) throw new AppException(ERROR_CODE.PARAM_NOT_POSITIVE, metadata.data);
return asNumber;
}
}
Loading