Compare commits
142
Commits
50d3bc5265
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f64f13b545 | ||
|
|
3caad838f6 | ||
|
|
f5ba267f78 | ||
|
|
753237ee83 | ||
|
|
c9f58a81f1 | ||
|
|
0d4ddc8f0e | ||
|
|
8e313c9b04 | ||
|
|
bdf43b6a96 | ||
|
|
80bc815d20 | ||
|
|
ae75a79c2f | ||
|
|
5c447c7f2c | ||
|
|
868572a1e2 | ||
|
|
05529d299b | ||
|
|
78c155c910 | ||
|
|
b809932fc2 | ||
|
|
d79af25e04 | ||
|
|
7d46b7bbf3 | ||
|
|
6839dbb701 | ||
|
|
23d56229ae | ||
|
|
3eee920a58 | ||
|
|
acec011bc1 | ||
|
|
c46edbfdca | ||
|
|
e7a189153d | ||
|
|
7f8caf7df8 | ||
|
|
d58406ff56 | ||
|
|
28c7aa54bb | ||
|
|
5626ff10f3 | ||
|
|
730a41d81e | ||
|
|
d2f2bbaabb | ||
|
|
4b872cf32f | ||
|
|
a16b07b8e0 | ||
|
|
476623b9fd | ||
|
|
2f351b8302 | ||
|
|
824815b921 | ||
|
|
b313c62814 | ||
|
|
866d8ca1b2 | ||
|
|
223bce143b | ||
|
|
a8ca887f3d | ||
|
|
e402d75610 | ||
|
|
6b2ffd017c | ||
|
|
65ae32dc87 | ||
|
|
4cbb2ba64c | ||
|
|
73e767322b | ||
|
|
2bb29b681c | ||
|
|
24c508187b | ||
|
|
670a8c5b46 | ||
|
|
43607842e6 | ||
|
|
4c822300c4 | ||
|
|
7ff7dd71a8 | ||
|
|
ca1c11ff18 | ||
|
|
28aa0abcec | ||
|
|
1210016142 | ||
|
|
6cdbe702fc | ||
|
|
ce23a75b8e | ||
|
|
4ae50fca11 | ||
|
|
d615467ee5 | ||
|
|
c948fff21d | ||
|
|
5608459355 | ||
|
|
7c06fc9c00 | ||
|
|
f240713dc0 | ||
|
|
1df6166649 | ||
|
|
e46a16735c | ||
|
|
489edf22e7 | ||
|
|
d117e7b925 | ||
|
|
0a4f3d59f8 | ||
|
|
b581acc1fe | ||
|
|
450627b091 | ||
|
|
740b88eceb | ||
|
|
18945edb51 | ||
|
|
0982f81dba | ||
|
|
7d08391ce0 | ||
|
|
ceaf615a24 | ||
|
|
64ec020cc8 | ||
|
|
72df8e473d | ||
|
|
ce6d713ec7 | ||
|
|
2ff4711bf6 | ||
|
|
b93f935564 | ||
|
|
641d0926e9 | ||
|
|
99e742f840 | ||
|
|
de725dffd7 | ||
|
|
f22da94ab4 | ||
|
|
a1283bf210 | ||
|
|
c4b5de6ef2 | ||
|
|
bceffda1e8 | ||
|
|
6b82af49ae | ||
|
|
31b3893ff1 | ||
|
|
260397c340 | ||
|
|
d030234c1f | ||
|
|
7d47fbd8de | ||
|
|
4f4ca28682 | ||
|
|
53126dd7e4 | ||
|
|
6c39a54b3b | ||
|
|
279d027944 | ||
|
|
fd58681c1b | ||
|
|
cf4bce12eb | ||
|
|
0823ffc5cf | ||
|
|
c8635c4d09 | ||
|
|
39878644e8 | ||
|
|
b8af145325 | ||
|
|
b030d29b11 | ||
|
|
7842050ed1 | ||
|
|
7848f9d4b0 | ||
|
|
0419cc5b1a | ||
|
|
a328a0a933 | ||
|
|
bfbf80f312 | ||
|
|
1641d4a027 | ||
|
|
dc0e62bac3 | ||
|
|
31fc17fd40 | ||
|
|
dd6d1d3060 | ||
|
|
51ae2eb984 | ||
|
|
a9af96e403 | ||
|
|
5c75ad93b5 | ||
|
|
ff3cc7bc5d | ||
|
|
70ae550733 | ||
|
|
240fe6580b | ||
|
|
4b9acacaec | ||
|
|
ba0a2ea7df | ||
|
|
e3624adb92 | ||
|
|
7ff22febe4 | ||
|
|
67b00b9d6f | ||
|
|
804c9e92a4 | ||
|
|
c3be8f9569 | ||
|
|
cc8de8cba2 | ||
|
|
b1925539a8 | ||
|
|
56bddbda7b | ||
|
|
3d48f9f19b | ||
|
|
8ef3deafb2 | ||
|
|
d687b2344b | ||
|
|
3003002c9c | ||
|
|
1fded57daa | ||
|
|
6c2ebe9cab | ||
|
|
ae6ee552c8 | ||
|
|
b0f3214a34 | ||
|
|
e038cab520 | ||
|
|
a783c1a829 | ||
|
|
fa40962c09 | ||
|
|
ff1171950b | ||
|
|
5900b73556 | ||
|
|
d462b2a2b0 | ||
|
|
2afeef699b | ||
|
|
1d17c216e9 | ||
|
|
ab1e5a4121 |
@@ -55,3 +55,10 @@ pids
|
|||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|
||||||
|
# Tests bdd
|
||||||
|
.vscode/
|
||||||
|
BDD.sql
|
||||||
|
migrations/
|
||||||
|
src/seed/
|
||||||
|
|||||||
Generated
+15
-5
@@ -9,7 +9,7 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.0.1",
|
"@nestjs/common": "^11.1.6",
|
||||||
"@nestjs/config": "^4.0.2",
|
"@nestjs/config": "^4.0.2",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/jwt": "^11.0.0",
|
"@nestjs/jwt": "^11.0.0",
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"@nestjs/typeorm": "^11.0.0",
|
"@nestjs/typeorm": "^11.0.0",
|
||||||
"@sentry/nestjs": "^10.10.0",
|
"@sentry/nestjs": "^10.10.0",
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
|
"bcryptjs": "^3.0.2",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.2",
|
"class-validator": "^0.14.2",
|
||||||
"joi": "^18.0.0",
|
"joi": "^18.0.0",
|
||||||
@@ -33,7 +34,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
"@eslint/js": "^9.18.0",
|
"@eslint/js": "^9.18.0",
|
||||||
"@nestjs/cli": "^11.0.0",
|
"@nestjs/cli": "^11.0.10",
|
||||||
"@nestjs/schematics": "^11.0.0",
|
"@nestjs/schematics": "^11.0.0",
|
||||||
"@nestjs/testing": "^11.0.1",
|
"@nestjs/testing": "^11.0.1",
|
||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
@@ -2321,9 +2322,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@nestjs/common": {
|
"node_modules/@nestjs/common": {
|
||||||
"version": "11.1.5",
|
"version": "11.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/@nestjs/common/-/common-11.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@nestjs/common/-/common-11.1.6.tgz",
|
||||||
"integrity": "sha512-DQpWdr3ShO0BHWkHl3I4W/jR6R3pDtxyBlmrpTuZF+PXxQyBXNvsUne0Wyo6QHPEDi+pAz9XchBFoKbqOhcdTg==",
|
"integrity": "sha512-krKwLLcFmeuKDqngG2N/RuZHCs2ycsKcxWIDgcm7i1lf3sQ0iG03ci+DsP/r3FcT/eJDFsIHnKtNta2LIi7PzQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"file-type": "21.0.0",
|
"file-type": "21.0.0",
|
||||||
@@ -5003,6 +5004,15 @@
|
|||||||
"node": ">= 18"
|
"node": ">= 18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bcryptjs": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-k38b3XOZKv60C4E2hVsXTolJWfkGRMbILBIe2IBITXciy5bOsTKot5kDrf3ZfufQtQOUN5mXceUEpU1rTl9Uog==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"bin": {
|
||||||
|
"bcrypt": "bin/bcrypt"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/bl": {
|
"node_modules/bl": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
|
||||||
|
|||||||
+3
-2
@@ -22,7 +22,7 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.0.1",
|
"@nestjs/common": "^11.1.6",
|
||||||
"@nestjs/config": "^4.0.2",
|
"@nestjs/config": "^4.0.2",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/jwt": "^11.0.0",
|
"@nestjs/jwt": "^11.0.0",
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
"@nestjs/typeorm": "^11.0.0",
|
"@nestjs/typeorm": "^11.0.0",
|
||||||
"@sentry/nestjs": "^10.10.0",
|
"@sentry/nestjs": "^10.10.0",
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
|
"bcryptjs": "^3.0.2",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.2",
|
"class-validator": "^0.14.2",
|
||||||
"joi": "^18.0.0",
|
"joi": "^18.0.0",
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
"@eslint/js": "^9.18.0",
|
"@eslint/js": "^9.18.0",
|
||||||
"@nestjs/cli": "^11.0.0",
|
"@nestjs/cli": "^11.0.10",
|
||||||
"@nestjs/schematics": "^11.0.0",
|
"@nestjs/schematics": "^11.0.0",
|
||||||
"@nestjs/testing": "^11.0.1",
|
"@nestjs/testing": "^11.0.1",
|
||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
|
|||||||
@@ -9,4 +9,9 @@ export class AppController {
|
|||||||
getOverView() {
|
getOverView() {
|
||||||
return this.appService.getOverView();
|
return this.appService.getOverView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('hello')
|
||||||
|
getHello(): string {
|
||||||
|
return this.appService.getHello();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { ParentsModule } from './routes/parents/parents.module';
|
|||||||
import { AuthModule } from './routes/auth/auth.module';
|
import { AuthModule } from './routes/auth/auth.module';
|
||||||
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
|
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
|
||||||
import { AllExceptionsFilter } from './common/filters/all_exceptions.filters';
|
import { AllExceptionsFilter } from './common/filters/all_exceptions.filters';
|
||||||
|
import { EnfantsModule } from './routes/enfants/enfants.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -46,6 +47,7 @@ import { AllExceptionsFilter } from './common/filters/all_exceptions.filters';
|
|||||||
}),
|
}),
|
||||||
UserModule,
|
UserModule,
|
||||||
ParentsModule,
|
ParentsModule,
|
||||||
|
EnfantsModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return 'Hello World!';
|
return 'Hello Test!!!';
|
||||||
}
|
}
|
||||||
|
|
||||||
getOverView() {
|
getOverView() {
|
||||||
|
|||||||
@@ -5,42 +5,45 @@ import { Request } from 'express';
|
|||||||
import { IS_PUBLIC_KEY } from "../decorators/public.decorator";
|
import { IS_PUBLIC_KEY } from "../decorators/public.decorator";
|
||||||
import { ConfigService } from "@nestjs/config";
|
import { ConfigService } from "@nestjs/config";
|
||||||
|
|
||||||
interface AuthenticatedRequest extends Request {
|
|
||||||
user?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly jwtService: JwtService,
|
private readonly jwtService: JwtService,
|
||||||
private readonly reflector: Reflector,
|
private readonly reflector: Reflector,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
||||||
|
context.getHandler(),
|
||||||
|
context.getClass(),
|
||||||
|
]);
|
||||||
|
if (isPublic) return true;
|
||||||
|
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
const request = context.switchToHttp().getRequest<Request>();
|
||||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
if (request.path.startsWith('/api-docs')) {
|
||||||
context.getHandler(),
|
return true;
|
||||||
context.getClass(),
|
|
||||||
]);
|
|
||||||
if (isPublic) return true;
|
|
||||||
|
|
||||||
const request = context.switchToHttp().getRequest<Request>();
|
|
||||||
const authHeader = request.headers['authorization'] as string | undefined;
|
|
||||||
|
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
||||||
throw new UnauthorizedException('Token manquant ou invalide');
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = authHeader.split(' ')[1];
|
|
||||||
try {
|
|
||||||
const payload = await this.jwtService.verifyAsync(token,
|
|
||||||
{ secret: this.configService.get<string>('jwt.secret') },
|
|
||||||
);
|
|
||||||
request.user = payload;
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
throw new UnauthorizedException('Token invalide ou expire');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
const authHeader = request.headers['authorization'] as string | undefined;
|
||||||
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||||
|
throw new UnauthorizedException('Token manquant ou invalide');
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = authHeader.split(' ')[1];
|
||||||
|
try {
|
||||||
|
const payload = await this.jwtService.verifyAsync(token, {
|
||||||
|
secret: this.configService.get<string>('jwt.accessSecret'),
|
||||||
|
});
|
||||||
|
|
||||||
|
request.user = {
|
||||||
|
...payload,
|
||||||
|
id: payload.sub,
|
||||||
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw new UnauthorizedException('Token invalide ou expiré');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { registerAs } from '@nestjs/config';
|
import { registerAs } from '@nestjs/config';
|
||||||
|
|
||||||
export default registerAs('jwt', () => ({
|
export default registerAs('jwt', () => ({
|
||||||
secret: process.env.JWT_SECRET,
|
accessSecret: process.env.JWT_ACCESS_SECRET,
|
||||||
expiresIn: process.env.JWT_EXPIRATION_TIME,
|
accessExpiresIn: process.env.JWT_ACCESS_EXPIRES,
|
||||||
|
refreshSecret: process.env.JWT_REFRESH_SECRET,
|
||||||
|
refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES,
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export const configValidationSchema = Joi.object({
|
|||||||
POSTGRES_DB: Joi.string().required(),
|
POSTGRES_DB: Joi.string().required(),
|
||||||
|
|
||||||
// JWT
|
// JWT
|
||||||
JWT_SECRET: Joi.string().required(),
|
JWT_ACCESS_SECRET: Joi.string().required(),
|
||||||
JWT_EXPIRATION_TIME: Joi.string().required(),
|
JWT_ACCESS_EXPIRES: Joi.string().required(),
|
||||||
|
JWT_REFRESH_SECRET: Joi.string().required(),
|
||||||
|
JWT_REFRESH_EXPIRES: Joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import {
|
import { Entity, PrimaryColumn, Column, OneToOne, JoinColumn } from 'typeorm';
|
||||||
Entity, PrimaryColumn, Column, OneToOne, JoinColumn
|
|
||||||
} from 'typeorm';
|
|
||||||
import { Users } from './users.entity';
|
import { Users } from './users.entity';
|
||||||
|
|
||||||
@Entity('assistantes_maternelles')
|
@Entity('assistantes_maternelles')
|
||||||
@@ -9,22 +7,15 @@ export class AssistanteMaternelle {
|
|||||||
@PrimaryColumn('uuid', { name: 'id_utilisateur' })
|
@PrimaryColumn('uuid', { name: 'id_utilisateur' })
|
||||||
user_id: string;
|
user_id: string;
|
||||||
|
|
||||||
@OneToOne(() => Users, user => user.assistanteMaternelle, { onDelete: 'CASCADE' })
|
@OneToOne(() => Users, (user) => user.assistanteMaternelle, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
||||||
user: Users;
|
user: Users;
|
||||||
|
|
||||||
@Column({ name: 'numero_agrement', length: 50, nullable: true })
|
@Column({ name: 'numero_agrement', length: 50, nullable: true })
|
||||||
approval_number?: string;
|
approval_number?: string;
|
||||||
|
|
||||||
@Column({ name: 'date_naissance', type: 'date', nullable: true })
|
|
||||||
birthdate?: Date;
|
|
||||||
|
|
||||||
@Column({ name: 'ville_naissance', length: 100, nullable: true })
|
|
||||||
birthplace_city?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'pays_naissance', length: 2, nullable: true })
|
|
||||||
birthplace_country?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'nir_chiffre', length: 15, nullable: true })
|
@Column({ name: 'nir_chiffre', length: 15, nullable: true })
|
||||||
nir?: string;
|
nir?: string;
|
||||||
|
|
||||||
@@ -34,9 +25,27 @@ export class AssistanteMaternelle {
|
|||||||
@Column({ name: 'biographie', type: 'text', nullable: true })
|
@Column({ name: 'biographie', type: 'text', nullable: true })
|
||||||
biography?: string;
|
biography?: string;
|
||||||
|
|
||||||
@Column({ name: 'disponible', type: 'boolean', default: true, nullable: true })
|
@Column({
|
||||||
|
name: 'disponible',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
available?: boolean;
|
available?: boolean;
|
||||||
|
|
||||||
@Column({ name: 'ville_residence', length: 100, nullable: true })
|
@Column({ name: 'ville_residence', length: 100, nullable: true })
|
||||||
residence_city?: string;
|
residence_city?: string;
|
||||||
|
|
||||||
|
@Column( { name: 'date_agrement', type: 'date', nullable: true })
|
||||||
|
agreement_date?: Date;
|
||||||
|
|
||||||
|
@Column( { name: 'annee_experience', type: 'smallint', nullable: true })
|
||||||
|
years_experience?: number;
|
||||||
|
|
||||||
|
@Column( { name: 'specialite', length: 100, nullable: true })
|
||||||
|
specialty?: string;
|
||||||
|
|
||||||
|
@Column( { name: 'place_disponible', type: 'integer', nullable: true })
|
||||||
|
places_available?: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,21 +47,21 @@ export class Children {
|
|||||||
gender?: GenreType;
|
gender?: GenreType;
|
||||||
|
|
||||||
@Column({ type: 'date', nullable: true, name: 'date_naissance' })
|
@Column({ type: 'date', nullable: true, name: 'date_naissance' })
|
||||||
birthdate?: Date;
|
birth_date?: Date;
|
||||||
|
|
||||||
@Column({ type: 'date', nullable: true, name: 'date_prevue_naissance' })
|
@Column({ type: 'date', nullable: true, name: 'date_prevue_naissance' })
|
||||||
due_date?: Date;
|
due_date?: Date;
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'photo_url' })
|
@Column({ nullable: true, name: 'photo_url', type: 'text' })
|
||||||
photo_url?: string;
|
photo_url?: string;
|
||||||
|
|
||||||
@Column({ default: false, name: 'consentement_photo' })
|
@Column({ default: false, name: 'consentement_photo', type: 'boolean' })
|
||||||
consent_photo: boolean;
|
consent_photo: boolean;
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'date_consentement_photo' })
|
@Column({ type: 'timestamptz', nullable: true, name: 'date_consentement_photo' })
|
||||||
consent_photo_at?: Date;
|
consent_photo_at?: Date;
|
||||||
|
|
||||||
@Column({ default: false, name: 'est_multiple' })
|
@Column({ default: false, name: 'est_multiple', type: 'boolean' })
|
||||||
is_multiple: boolean;
|
is_multiple: boolean;
|
||||||
|
|
||||||
// Lien via table de jointure enfants_parents
|
// Lien via table de jointure enfants_parents
|
||||||
|
|||||||
@@ -28,9 +28,13 @@ export class Contrat {
|
|||||||
@Column({type: 'numeric', precision: 6, scale: 2, nullable: true, name: 'indemnites_repas'})
|
@Column({type: 'numeric', precision: 6, scale: 2, nullable: true, name: 'indemnites_repas'})
|
||||||
meal_indemnity?: string;
|
meal_indemnity?: string;
|
||||||
|
|
||||||
|
@Column( { name: 'date_debut', type: 'date', nullable: true })
|
||||||
|
start_date?: Date;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
enum: StatutContratType,
|
enum: StatutContratType,
|
||||||
|
enumName: 'statut_contrat_type',
|
||||||
default: StatutContratType.BROUILLON,
|
default: StatutContratType.BROUILLON,
|
||||||
name: 'statut'
|
name: 'statut'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export enum StatutDossierType {
|
|||||||
ENVOYE = 'envoye',
|
ENVOYE = 'envoye',
|
||||||
ACCEPTE = 'accepte',
|
ACCEPTE = 'accepte',
|
||||||
REFUSE = 'refuse',
|
REFUSE = 'refuse',
|
||||||
|
CLOTURE = 'cloture',
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity('dossiers')
|
@Entity('dossiers')
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Users } from './users.entity';
|
|||||||
import { ParentsChildren } from './parents_children.entity';
|
import { ParentsChildren } from './parents_children.entity';
|
||||||
import { Dossier } from './dossiers.entity';
|
import { Dossier } from './dossiers.entity';
|
||||||
|
|
||||||
@Entity('parents')
|
@Entity('parents', { schema: 'public' })
|
||||||
export class Parents {
|
export class Parents {
|
||||||
// PK = FK vers utilisateurs.id
|
// PK = FK vers utilisateurs.id
|
||||||
@PrimaryColumn('uuid', { name: 'id_utilisateur' })
|
@PrimaryColumn('uuid', { name: 'id_utilisateur' })
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import {
|
|||||||
import { Parents } from './parents.entity';
|
import { Parents } from './parents.entity';
|
||||||
import { Children } from './children.entity';
|
import { Children } from './children.entity';
|
||||||
|
|
||||||
@Entity('enfants_parents')
|
@Entity('enfants_parents', { schema: 'public' })
|
||||||
export class ParentsChildren {
|
export class ParentsChildren {
|
||||||
@PrimaryColumn('uuid', { name: 'id_parent' })
|
@PrimaryColumn('uuid', { name: 'id_parent' })
|
||||||
id_parent: string;
|
parentId: string;
|
||||||
|
|
||||||
@PrimaryColumn('uuid', { name: 'id_enfant' })
|
@PrimaryColumn('uuid', { name: 'id_enfant' })
|
||||||
id_enfant: string;
|
enfantId: string;
|
||||||
|
|
||||||
@ManyToOne(() => Parents, p => p.parentChildren, { onDelete: 'CASCADE' })
|
@ManyToOne(() => Parents, p => p.parentChildren, { onDelete: 'CASCADE' })
|
||||||
@JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
|
@JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export enum RoleType {
|
|||||||
GESTIONNAIRE = 'gestionnaire',
|
GESTIONNAIRE = 'gestionnaire',
|
||||||
SUPER_ADMIN = 'super_admin',
|
SUPER_ADMIN = 'super_admin',
|
||||||
ASSISTANTE_MATERNELLE = 'assistante_maternelle',
|
ASSISTANTE_MATERNELLE = 'assistante_maternelle',
|
||||||
|
ADMINISTRATEUR = 'administrateur',
|
||||||
}
|
}
|
||||||
|
|
||||||
//Enum pour definir le genre
|
//Enum pour definir le genre
|
||||||
@@ -29,23 +30,34 @@ export enum StatutUtilisateurType {
|
|||||||
SUSPENDU = 'suspendu',
|
SUSPENDU = 'suspendu',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum SituationFamilialeType {
|
||||||
|
CELIBATAIRE = 'celibataire',
|
||||||
|
MARIE = 'marie',
|
||||||
|
DIVORCE = 'divorce',
|
||||||
|
VEUF = 'veuf',
|
||||||
|
PACSE = 'pacse',
|
||||||
|
SEPARE = 'separe',
|
||||||
|
PARENT_ISOLE = 'parent_isole',
|
||||||
|
CONCUBINAGE = 'concubinage',
|
||||||
|
}
|
||||||
|
|
||||||
//Declaration de l'entite utilisateur
|
//Declaration de l'entite utilisateur
|
||||||
@Entity('utilisateurs', { schema: 'public' })
|
@Entity('utilisateurs', { schema: 'public' })
|
||||||
export class Users {
|
export class Users {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ unique: true, name: 'courriel' })
|
@Column({ unique: true, name: 'email' })
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
@Column({ name: 'mot_de_passe_hash' })
|
@Column({ name: 'password' })
|
||||||
password_hash: string;
|
password: string;
|
||||||
|
|
||||||
@Column({ name: 'prenom', nullable: true })
|
@Column({ name: 'prenom', nullable: true })
|
||||||
first_name?: string;
|
prenom?: string;
|
||||||
|
|
||||||
@Column({ name: 'nom', nullable: true })
|
@Column({ name: 'nom', nullable: true })
|
||||||
last_name?: string;
|
nom?: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
@@ -54,7 +66,7 @@ export class Users {
|
|||||||
nullable: true,
|
nullable: true,
|
||||||
name: 'genre'
|
name: 'genre'
|
||||||
})
|
})
|
||||||
gender?: GenreType;
|
genre?: GenreType;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
@@ -71,37 +83,57 @@ export class Users {
|
|||||||
default: StatutUtilisateurType.EN_ATTENTE,
|
default: StatutUtilisateurType.EN_ATTENTE,
|
||||||
name: 'statut'
|
name: 'statut'
|
||||||
})
|
})
|
||||||
status: StatutUtilisateurType;
|
statut: StatutUtilisateurType;
|
||||||
|
|
||||||
|
@Column({ type: 'enum',
|
||||||
|
enum: SituationFamilialeType,
|
||||||
|
enumName: 'situation_familiale_type',
|
||||||
|
nullable: true,
|
||||||
|
name: 'situation_familiale'
|
||||||
|
})
|
||||||
|
situation_familiale?: SituationFamilialeType;
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'telephone' })
|
@Column({ nullable: true, name: 'telephone' })
|
||||||
phone?: string;
|
telephone?: string;
|
||||||
|
|
||||||
|
@Column({ name: 'mobile', nullable: true })
|
||||||
|
mobile?: string;
|
||||||
|
|
||||||
|
@Column({ name: 'telephone_fixe', nullable: true })
|
||||||
|
telephone_fixe?: string;
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'adresse' })
|
@Column({ nullable: true, name: 'adresse' })
|
||||||
address?: string;
|
adresse?: string;
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'photo_url' })
|
@Column({ nullable: true, name: 'photo_url' })
|
||||||
photo_url?: string;
|
photo_url?: string;
|
||||||
|
|
||||||
@Column({ default: false, name: 'consentement_photo' })
|
@Column({ default: false, name: 'consentement_photo' })
|
||||||
consent_photo: boolean;
|
consentement_photo: boolean;
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'date_consentement_photo' })
|
@Column({ type: 'timestamptz', nullable: true, name: 'date_consentement_photo' })
|
||||||
consent_photo_at?: Date;
|
date_consentement_photo?: Date;
|
||||||
|
|
||||||
@Column({ default: false, name: 'changement_mdp_obligatoire' })
|
@Column({ default: false, name: 'changement_mdp_obligatoire' })
|
||||||
must_change_password: boolean;
|
changement_mdp_obligatoire: boolean;
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'ville' })
|
@Column({ nullable: true, name: 'ville' })
|
||||||
city?: string;
|
ville?: string;
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'code_postal' })
|
@Column({ nullable: true, name: 'code_postal' })
|
||||||
postal_code?: string;
|
code_postal?: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true, name: 'profession' })
|
||||||
|
profession?: string;
|
||||||
|
|
||||||
|
@Column({ name: 'date_naissance', type: 'date', nullable: true })
|
||||||
|
date_naissance?: Date;
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
||||||
created_at: Date;
|
cree_le: Date;
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
||||||
updated_at: Date;
|
modifie_le: Date;
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
@OneToOne(() => AssistanteMaternelle, a => a.user)
|
@OneToOne(() => AssistanteMaternelle, a => a.user)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class Validation {
|
|||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
||||||
user?: Users;
|
user?: Users;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 50, name: 'type' })
|
@Column({ type: 'varchar', length: 50, name: 'type', nullable: true })
|
||||||
type: string;
|
type: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
@@ -28,9 +28,17 @@ export class Validation {
|
|||||||
})
|
})
|
||||||
status: StatutValidationType;
|
status: StatutValidationType;
|
||||||
|
|
||||||
|
@ManyToOne(() => Users, { nullable: true })
|
||||||
|
@JoinColumn({ name: 'valide_par', referencedColumnName: 'id' })
|
||||||
|
validated_by?: Users;
|
||||||
|
|
||||||
|
@Column( { name: 'commentaire', type: 'text', nullable: true })
|
||||||
|
comment?: string;
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
||||||
created_at: Date;
|
created_at: Date;
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
||||||
updated_at: Date;
|
updated_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -41,10 +41,11 @@ async function bootstrap() {
|
|||||||
},
|
},
|
||||||
'access-token',
|
'access-token',
|
||||||
)
|
)
|
||||||
|
//.addServer('/api/v1')
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const document = SwaggerModule.createDocument(app, config);
|
const document = SwaggerModule.createDocument(app, config);
|
||||||
SwaggerModule.setup('api-docs', app, document);
|
SwaggerModule.setup('api/v1/swagger', app, document);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,22 +6,28 @@ import {
|
|||||||
Patch,
|
Patch,
|
||||||
Param,
|
Param,
|
||||||
Delete,
|
Delete,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
||||||
import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
import { Roles } from 'src/common/decorators/roles.decorator';
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
import { RoleType } from 'src/entities/users.entity';
|
||||||
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
||||||
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
||||||
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
|
|
||||||
@ApiTags("Assistantes Maternelles")
|
@ApiTags("Assistantes Maternelles")
|
||||||
|
@ApiBearerAuth('access-token')
|
||||||
|
@UseGuards(AuthGuard, RolesGuard)
|
||||||
@Controller('assistantes-maternelles')
|
@Controller('assistantes-maternelles')
|
||||||
export class AssistantesMaternellesController {
|
export class AssistantesMaternellesController {
|
||||||
constructor(private readonly assistantesMaternellesService: AssistantesMaternellesService) {}
|
constructor(private readonly assistantesMaternellesService: AssistantesMaternellesService) { }
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@ApiResponse({ status: 201, description: 'Assistante maternelle créée avec succès' })
|
@ApiOperation({ summary: 'Créer nounou' })
|
||||||
|
@ApiResponse({ status: 201, description: 'Nounou créée avec succès' })
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||||
@ApiBody({ type: CreateAssistanteDto })
|
@ApiBody({ type: CreateAssistanteDto })
|
||||||
@Post()
|
@Post()
|
||||||
@@ -31,7 +37,8 @@ export class AssistantesMaternellesController {
|
|||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@Get()
|
@Get()
|
||||||
@ApiResponse({ status: 200, description: 'Liste des assistantes maternelles' })
|
@ApiOperation({ summary: 'Récupérer la liste des nounous' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Liste des nounous' })
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||||
getAll(): Promise<AssistanteMaternelle[]> {
|
getAll(): Promise<AssistanteMaternelle[]> {
|
||||||
return this.assistantesMaternellesService.findAll();
|
return this.assistantesMaternellesService.findAll();
|
||||||
@@ -39,8 +46,10 @@ export class AssistantesMaternellesController {
|
|||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiResponse({ status: 200, description: 'Détails de l\'assistante maternelle' })
|
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||||
@ApiResponse({ status: 404, description: 'Assistante maternelle non trouvée' })
|
@ApiOperation({ summary: 'Récupérer une nounou par id' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Détails de la nounou' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Nounou non trouvée' })
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||||
getOne(@Param('id') user_id: string): Promise<AssistanteMaternelle> {
|
getOne(@Param('id') user_id: string): Promise<AssistanteMaternelle> {
|
||||||
return this.assistantesMaternellesService.findOne(user_id);
|
return this.assistantesMaternellesService.findOne(user_id);
|
||||||
@@ -48,20 +57,25 @@ export class AssistantesMaternellesController {
|
|||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@ApiBody({ type: UpdateAssistanteDto })
|
@ApiBody({ type: UpdateAssistanteDto })
|
||||||
@ApiResponse({ status: 200, description: 'Assistante maternelle mise à jour avec succès' })
|
@ApiOperation({ summary: 'Mettre à jour une nounou' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Nounou mise à jour avec succès' })
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
||||||
@ApiResponse({ status: 404, description: 'Assistante maternelle non trouvée' })
|
@ApiResponse({ status: 404, description: 'Nounou non trouvée' })
|
||||||
|
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
update(@Param('id') id: string, @Body() dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
||||||
return this.assistantesMaternellesService.update(id, dto);
|
return this.assistantesMaternellesService.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||||
@ApiResponse({ status: 200, description: 'Assistante maternelle supprimée avec succès' })
|
@ApiOperation({ summary: 'Supprimer une nounou' })
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins et gestionnaires' })
|
@ApiResponse({ status: 200, description: 'Nounou supprimée avec succès' })
|
||||||
@ApiResponse({ status: 404, description: 'Assistante maternelle non trouvée' })
|
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins, gestionnaires et administrateurs' })
|
||||||
|
@ApiResponse({ status: 404, description: 'Nounou non trouvée' })
|
||||||
|
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
remove(@Param('id') id: string): Promise<void> {
|
remove(@Param('id') id: string): Promise<{ message: string }>
|
||||||
|
{
|
||||||
return this.assistantesMaternellesService.remove(id);
|
return this.assistantesMaternellesService.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
||||||
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
||||||
|
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Users } from 'src/entities/users.entity';
|
||||||
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([AssistanteMaternelle, Users]),
|
||||||
|
AuthModule
|
||||||
|
],
|
||||||
controllers: [AssistantesMaternellesController],
|
controllers: [AssistantesMaternellesController],
|
||||||
providers: [AssistantesMaternellesService],
|
providers: [AssistantesMaternellesService],
|
||||||
|
exports: [
|
||||||
|
AssistantesMaternellesService,
|
||||||
|
TypeOrmModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class AssistantesMaternellesModule {}
|
export class AssistantesMaternellesModule { }
|
||||||
|
|||||||
@@ -34,15 +34,16 @@ export class AssistantesMaternellesService {
|
|||||||
const entity = this.assistantesMaternelleRepository.create({
|
const entity = this.assistantesMaternelleRepository.create({
|
||||||
user_id: dto.user_id,
|
user_id: dto.user_id,
|
||||||
user: { ...user, role: RoleType.ASSISTANTE_MATERNELLE },
|
user: { ...user, role: RoleType.ASSISTANTE_MATERNELLE },
|
||||||
approval_number: dto.numero_agrement,
|
approval_number: dto.approval_number,
|
||||||
birthdate: dto.date_naissance ? new Date(dto.date_naissance) : undefined,
|
nir: dto.nir,
|
||||||
birthplace_city: dto.ville_naissance,
|
max_children: dto.max_children,
|
||||||
birthplace_country: dto.pays_naissance,
|
biography: dto.biography,
|
||||||
nir: dto.nir_chiffre,
|
available: dto.available ?? true,
|
||||||
max_children: dto.nb_max_enfants,
|
residence_city: dto.residence_city,
|
||||||
biography: dto.biographie,
|
agreement_date: dto.agreement_date ? new Date(dto.agreement_date) : undefined,
|
||||||
available: dto.disponible ?? true,
|
years_experience: dto.years_experience,
|
||||||
residence_city: dto.ville_residence,
|
specialty: dto.specialty,
|
||||||
|
places_available: dto.places_available,
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.assistantesMaternelleRepository.save(entity);
|
return this.assistantesMaternelleRepository.save(entity);
|
||||||
@@ -71,8 +72,9 @@ export class AssistantesMaternellesService {
|
|||||||
return this.findOne(id);
|
return this.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppression
|
// Suppression d’une assistante maternelle
|
||||||
async remove(id: string): Promise<void> {
|
async remove(id: string): Promise<{ message: string }> {
|
||||||
await this.assistantesMaternelleRepository.delete(id);
|
await this.assistantesMaternelleRepository.delete(id);
|
||||||
|
return { message: 'Assistante maternelle supprimée' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Req, UnauthorizedException, UseGuards } from '@nestjs/common';
|
||||||
import { LoginDto } from '../user/dto/login.dto';
|
import { LoginDto } from './dto/login.dto';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { Public } from 'src/common/decorators/public.decorator';
|
import { Public } from 'src/common/decorators/public.decorator';
|
||||||
import { RegisterDto } from '../user/dto/register.dto';
|
import { RegisterDto } from './dto/register.dto';
|
||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
|
import type { Request } from 'express';
|
||||||
|
import { UserService } from '../user/user.service';
|
||||||
|
import { ProfileResponseDto } from './dto/profile_response.dto';
|
||||||
|
import { RefreshTokenDto } from './dto/refresh_token.dto';
|
||||||
|
import { User } from 'src/common/decorators/user.decorator';
|
||||||
|
import { Users } from 'src/entities/users.entity';
|
||||||
|
|
||||||
@ApiTags('Authentification')
|
@ApiTags('Authentification')
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly authService: AuthService) { }
|
constructor(
|
||||||
|
private readonly authService: AuthService,
|
||||||
|
private readonly userService: UserService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
@ApiOperation({ summary: 'Connexion' })
|
@ApiOperation({ summary: 'Connexion' })
|
||||||
@@ -27,16 +37,39 @@ export class AuthController {
|
|||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
@Post('refresh')
|
@Post('refresh')
|
||||||
|
@ApiBearerAuth('refresh_token')
|
||||||
|
@ApiResponse({ status: 200, description: 'Nouveaux tokens générés avec succès.' })
|
||||||
|
@ApiResponse({ status: 401, description: 'Token de rafraîchissement invalide ou expiré.' })
|
||||||
@ApiOperation({ summary: 'Rafraichir les tokens' })
|
@ApiOperation({ summary: 'Rafraichir les tokens' })
|
||||||
async refresh(@Body('refresh_token') refreshToken: string) {
|
async refresh(@Body() dto: RefreshTokenDto) {
|
||||||
return this.authService.refreshTokens(refreshToken);
|
return this.authService.refreshTokens(dto.refresh_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get('me')
|
@Get('me')
|
||||||
// @UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
// @ApiBearerAuth('access-token')
|
@ApiBearerAuth('access-token')
|
||||||
// @ApiOperation({ summary: "Recuperer le profil de l'utilisateur connecte"})
|
@ApiOperation({ summary: "Récupérer le profil complet de l'utilisateur connecté" })
|
||||||
// getProfile(@Request() req) {
|
@ApiResponse({ status: 200, type: ProfileResponseDto })
|
||||||
// return req.user;
|
async getProfile(@Req() req: Request): Promise<ProfileResponseDto> {
|
||||||
// }
|
if (!req.user || !req.user.sub) {
|
||||||
|
throw new UnauthorizedException('Utilisateur non authentifié');
|
||||||
|
}
|
||||||
|
const user = await this.userService.findOne(req.user.sub);
|
||||||
|
return {
|
||||||
|
id: user.id,
|
||||||
|
email: user.email,
|
||||||
|
role: user.role,
|
||||||
|
prenom: user.prenom ?? '',
|
||||||
|
nom: user.nom ?? '',
|
||||||
|
statut: user.statut,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@ApiBearerAuth('access-token')
|
||||||
|
@Post('logout')
|
||||||
|
logout(@User() currentUser: Users) {
|
||||||
|
return this.authService.logout(currentUser.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import {
|
|||||||
import { UserService } from '../user/user.service';
|
import { UserService } from '../user/user.service';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { RegisterDto } from '../user/dto/register.dto';
|
import { RegisterDto } from './dto/register.dto';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { RoleType, StatutUtilisateurType, Users } from 'src/entities/users.entity';
|
import { RoleType, StatutUtilisateurType, Users } from 'src/entities/users.entity';
|
||||||
import { LoginDto } from '../user/dto/login.dto';
|
import { LoginDto } from './dto/login.dto';
|
||||||
import { DeepPartial } from 'typeorm';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@@ -24,12 +23,14 @@ export class AuthService {
|
|||||||
* Génère un access_token et un refresh_token
|
* Génère un access_token et un refresh_token
|
||||||
*/
|
*/
|
||||||
async generateTokens(userId: string, email: string, role: RoleType) {
|
async generateTokens(userId: string, email: string, role: RoleType) {
|
||||||
const secret = this.configService.get<string>('jwt.secret');
|
const accessSecret = this.configService.get<string>('jwt.accessSecret');
|
||||||
const expiresIn = this.configService.get<string>('jwt.expiresIn');
|
const accessExpiresIn = this.configService.get<string>('jwt.accessExpiresIn');
|
||||||
|
const refreshSecret = this.configService.get<string>('jwt.refreshSecret');
|
||||||
|
const refreshExpiresIn = this.configService.get<string>('jwt.refreshExpiresIn');
|
||||||
|
|
||||||
const [accessToken, refreshToken] = await Promise.all([
|
const [accessToken, refreshToken] = await Promise.all([
|
||||||
this.jwtService.signAsync({ sub: userId, email, role }, { secret, expiresIn }),
|
this.jwtService.signAsync({ sub: userId, email, role }, { secret: accessSecret, expiresIn: accessExpiresIn }),
|
||||||
this.jwtService.signAsync({ sub: userId }, { secret, expiresIn }),
|
this.jwtService.signAsync({ sub: userId }, { secret: refreshSecret, expiresIn: refreshExpiresIn }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -46,13 +47,19 @@ export class AuthService {
|
|||||||
const user = await this.usersService.findByEmailOrNull(dto.email);
|
const user = await this.usersService.findByEmailOrNull(dto.email);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new UnauthorizedException('Identifiants invalides');
|
throw new UnauthorizedException('Email invalide');
|
||||||
}
|
}
|
||||||
|
console.log("Tentative login:", dto.email, JSON.stringify(dto.password));
|
||||||
|
console.log("Utilisateur trouvé:", user.email, user.password);
|
||||||
|
|
||||||
const isMatch = await bcrypt.compare(dto.password, user.password_hash);
|
const isMatch = await bcrypt.compare(dto.password, user.password);
|
||||||
|
console.log("Résultat bcrypt.compare:", isMatch);
|
||||||
if (!isMatch) {
|
if (!isMatch) {
|
||||||
throw new UnauthorizedException('Identifiants invalides');
|
throw new UnauthorizedException('Mot de passe invalide');
|
||||||
}
|
}
|
||||||
|
// if (user.password !== dto.password) {
|
||||||
|
// throw new UnauthorizedException('Mot de passe invalide');
|
||||||
|
// }
|
||||||
|
|
||||||
return this.generateTokens(user.id, user.email, user.role);
|
return this.generateTokens(user.id, user.email, user.role);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -67,7 +74,7 @@ export class AuthService {
|
|||||||
async refreshTokens(refreshToken: string) {
|
async refreshTokens(refreshToken: string) {
|
||||||
try {
|
try {
|
||||||
const payload = await this.jwtService.verifyAsync(refreshToken, {
|
const payload = await this.jwtService.verifyAsync(refreshToken, {
|
||||||
secret: this.configService.get<string>('jwt.refresh_token_secret'),
|
secret: this.configService.get<string>('jwt.refreshSecret'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const user = await this.usersService.findOne(payload.sub);
|
const user = await this.usersService.findOne(payload.sub);
|
||||||
@@ -95,19 +102,18 @@ export class AuthService {
|
|||||||
registerDto.role = RoleType.PARENT;
|
registerDto.role = RoleType.PARENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerDto.status = StatutUtilisateurType.EN_ATTENTE;
|
registerDto.statut = StatutUtilisateurType.EN_ATTENTE;
|
||||||
|
|
||||||
if (!registerDto.consent_photo) {
|
if (!registerDto.consentement_photo) {
|
||||||
registerDto.consent_photo_at = null;
|
registerDto.date_consentement_photo = null;
|
||||||
} else if (registerDto.consent_photo_at) {
|
} else if (registerDto.date_consentement_photo) {
|
||||||
const date = new Date(registerDto.consent_photo_at);
|
const date = new Date(registerDto.date_consentement_photo);
|
||||||
if (isNaN(date.getTime())) {
|
if (isNaN(date.getTime())) {
|
||||||
registerDto.consent_photo_at = null;
|
registerDto.date_consentement_photo = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.usersService.createUser(registerDto);
|
const user = await this.usersService.createUser(registerDto);
|
||||||
|
|
||||||
const tokens = await this.generateTokens(user.id, user.email, user.role);
|
const tokens = await this.generateTokens(user.id, user.email, user.role);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -116,11 +122,16 @@ export class AuthService {
|
|||||||
id: user.id,
|
id: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
role: user.role,
|
role: user.role,
|
||||||
first_name: user.first_name,
|
prenom: user.prenom,
|
||||||
last_name: user.last_name,
|
nom: user.nom,
|
||||||
status: user.status,
|
statut: user.statut,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async logout(userId: string) {
|
||||||
|
// Pour le moment envoyer un message clair
|
||||||
|
return { success: true, message: 'Deconnexion'}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ApiProperty } from "@nestjs/swagger";
|
|||||||
import { IsEmail, IsString, MaxLength, MinLength } from "class-validator";
|
import { IsEmail, IsString, MaxLength, MinLength } from "class-validator";
|
||||||
|
|
||||||
export class LoginDto {
|
export class LoginDto {
|
||||||
@ApiProperty({ example: 'my.user@example.com', description: "Adresse email de l'utililisateur" })
|
@ApiProperty({ example: 'mon.utilisateur@exemple.com', description: "Adresse email de l'utililisateur" })
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export class LoginDto {
|
|||||||
description: "Mot de passe de l'utilisateur"
|
description: "Mot de passe de l'utilisateur"
|
||||||
})
|
})
|
||||||
@IsString({ message: 'Le mot de passe doit etre une chaine de caracteres' })
|
@IsString({ message: 'Le mot de passe doit etre une chaine de caracteres' })
|
||||||
@MinLength(8, { message: 'Le mot de passe doit contenir au moins 8 caracteres' })
|
//@MinLength(8, { message: 'Le mot de passe doit contenir au moins 8 caracteres' })
|
||||||
@MaxLength(50)
|
@MaxLength(50)
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { RoleType, StatutUtilisateurType } from 'src/entities/users.entity';
|
||||||
|
|
||||||
|
export class ProfileResponseDto {
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
email: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: RoleType })
|
||||||
|
role: RoleType;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
prenom?: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
nom?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: StatutUtilisateurType })
|
||||||
|
statut: StatutUtilisateurType;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
import { IsString } from "class-validator";
|
||||||
|
|
||||||
|
export class RefreshTokenDto {
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Token de rafraîchissement',
|
||||||
|
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
refresh_token: string;
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
import { ApiProperty, OmitType } from '@nestjs/swagger';
|
import { ApiProperty, OmitType } from '@nestjs/swagger';
|
||||||
import { IsEnum, IsOptional } from 'class-validator';
|
import { IsEnum, IsOptional } from 'class-validator';
|
||||||
import { CreateUserDto } from './create_user.dto';
|
import { CreateUserDto } from '../../user/dto/create_user.dto';
|
||||||
import { RoleType, StatutUtilisateurType } from 'src/entities/users.entity';
|
import { RoleType, StatutUtilisateurType } from 'src/entities/users.entity';
|
||||||
|
|
||||||
export class RegisterDto extends OmitType(CreateUserDto, ['must_change_password'] as const) {
|
export class RegisterDto extends OmitType(CreateUserDto, ['changement_mdp_obligatoire'] as const) {
|
||||||
@ApiProperty({ enum: [RoleType.ASSISTANTE_MATERNELLE, RoleType.PARENT], default: RoleType.PARENT })
|
@ApiProperty({ enum: [RoleType.ASSISTANTE_MATERNELLE, RoleType.PARENT], default: RoleType.PARENT })
|
||||||
@IsEnum(RoleType)
|
@IsEnum(RoleType)
|
||||||
role: RoleType = RoleType.PARENT;
|
role: RoleType = RoleType.PARENT;
|
||||||
|
|
||||||
@IsEnum(StatutUtilisateurType)
|
@IsEnum(StatutUtilisateurType)
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
status?: StatutUtilisateurType = StatutUtilisateurType.EN_ATTENTE;
|
statut?: StatutUtilisateurType = StatutUtilisateurType.EN_ATTENTE;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Module({})
|
||||||
|
export class DossiersModule {}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import {
|
||||||
|
IsBoolean,
|
||||||
|
IsDateString,
|
||||||
|
IsEnum,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
MaxLength,
|
||||||
|
ValidateIf,
|
||||||
|
} from 'class-validator';
|
||||||
|
import { GenreType, StatutEnfantType } from 'src/entities/children.entity';
|
||||||
|
|
||||||
|
export class CreateEnfantsDto {
|
||||||
|
@ApiProperty({ enum: StatutEnfantType, example: StatutEnfantType.ACTIF })
|
||||||
|
@IsEnum(StatutEnfantType)
|
||||||
|
@IsNotEmpty()
|
||||||
|
status: StatutEnfantType;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Georges', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@MaxLength(100)
|
||||||
|
first_name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Dupont', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@MaxLength(100)
|
||||||
|
last_name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: GenreType, required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsEnum(GenreType)
|
||||||
|
gender?: GenreType;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2018-06-24', required: false })
|
||||||
|
@ValidateIf(o => o.status !== StatutEnfantType.A_NAITRE)
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
birth_date?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2025-12-15', required: false })
|
||||||
|
@ValidateIf(o => o.status === StatutEnfantType.A_NAITRE)
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
due_date?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'https://monimage.com/photo.jpg', required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
photo_url?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ default: false })
|
||||||
|
@IsBoolean()
|
||||||
|
consent_photo: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsDateString()
|
||||||
|
consent_photo_at?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ default: false })
|
||||||
|
@IsBoolean()
|
||||||
|
is_multiple: boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { GenreType, StatutEnfantType } from 'src/entities/children.entity';
|
||||||
|
|
||||||
|
export class EnfantResponseDto {
|
||||||
|
@ApiProperty({ example: 'UUID-enfant' })
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: StatutEnfantType })
|
||||||
|
status: StatutEnfantType;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Georges', required: false })
|
||||||
|
first_name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Dupont', required: false })
|
||||||
|
last_name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: GenreType, required: false })
|
||||||
|
gender?: GenreType;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2018-06-24', required: false })
|
||||||
|
birth_date?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '2025-12-15', required: false })
|
||||||
|
due_date?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'https://monimage.com/photo.jpg', required: false })
|
||||||
|
photo_url?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: false })
|
||||||
|
consent_photo: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ example: false })
|
||||||
|
is_multiple: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'UUID-parent' })
|
||||||
|
parent_id: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/swagger';
|
||||||
|
import { CreateEnfantsDto } from './create_enfants.dto';
|
||||||
|
|
||||||
|
export class UpdateEnfantsDto extends PartialType(CreateEnfantsDto) {}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { EnfantsController } from './enfants.controller';
|
||||||
|
|
||||||
|
describe('EnfantsController', () => {
|
||||||
|
let controller: EnfantsController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [EnfantsController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<EnfantsController>(EnfantsController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Get,
|
||||||
|
Param,
|
||||||
|
ParseUUIDPipe,
|
||||||
|
Patch,
|
||||||
|
Post,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { EnfantsService } from './enfants.service';
|
||||||
|
import { CreateEnfantsDto } from './dto/create_enfants.dto';
|
||||||
|
import { UpdateEnfantsDto } from './dto/update_enfants.dto';
|
||||||
|
import { RoleType, Users } from 'src/entities/users.entity';
|
||||||
|
import { User } from 'src/common/decorators/user.decorator';
|
||||||
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
|
import { Roles } from 'src/common/decorators/roles.decorator';
|
||||||
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
|
|
||||||
|
@ApiBearerAuth('access-token')
|
||||||
|
@ApiTags('Enfants')
|
||||||
|
@UseGuards(AuthGuard, RolesGuard)
|
||||||
|
@Controller('enfants')
|
||||||
|
export class EnfantsController {
|
||||||
|
constructor(private readonly enfantsService: EnfantsService) { }
|
||||||
|
|
||||||
|
@Roles(RoleType.PARENT)
|
||||||
|
@Post()
|
||||||
|
create(@Body() dto: CreateEnfantsDto, @User() currentUser: Users) {
|
||||||
|
return this.enfantsService.create(dto, currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(RoleType.ADMINISTRATEUR, RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
||||||
|
@Get()
|
||||||
|
findAll() {
|
||||||
|
return this.enfantsService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(
|
||||||
|
RoleType.PARENT,
|
||||||
|
RoleType.ADMINISTRATEUR,
|
||||||
|
RoleType.SUPER_ADMIN,
|
||||||
|
RoleType.GESTIONNAIRE
|
||||||
|
)
|
||||||
|
@Get(':id')
|
||||||
|
findOne(
|
||||||
|
@Param('id', new ParseUUIDPipe()) id: string,
|
||||||
|
@User() currentUser: Users
|
||||||
|
) {
|
||||||
|
return this.enfantsService.findOne(id, currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(RoleType.ADMINISTRATEUR, RoleType.SUPER_ADMIN, RoleType.PARENT)
|
||||||
|
@Patch(':id')
|
||||||
|
update(
|
||||||
|
@Param('id', new ParseUUIDPipe()) id: string,
|
||||||
|
@Body() dto: UpdateEnfantsDto,
|
||||||
|
@User() currentUser: Users,
|
||||||
|
) {
|
||||||
|
return this.enfantsService.update(id, dto, currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(RoleType.SUPER_ADMIN)
|
||||||
|
@Delete(':id')
|
||||||
|
remove(@Param('id', new ParseUUIDPipe()) id: string) {
|
||||||
|
return this.enfantsService.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { EnfantsController } from './enfants.controller';
|
||||||
|
import { EnfantsService } from './enfants.service';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { Children } from 'src/entities/children.entity';
|
||||||
|
import { Parents } from 'src/entities/parents.entity';
|
||||||
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([Children, Parents, ParentsChildren]),
|
||||||
|
AuthModule
|
||||||
|
|
||||||
|
],
|
||||||
|
controllers: [EnfantsController],
|
||||||
|
providers: [EnfantsService]
|
||||||
|
})
|
||||||
|
export class EnfantsModule { }
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { EnfantsService } from './enfants.service';
|
||||||
|
|
||||||
|
describe('EnfantsService', () => {
|
||||||
|
let service: EnfantsService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [EnfantsService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<EnfantsService>(EnfantsService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
ConflictException,
|
||||||
|
ForbiddenException,
|
||||||
|
Injectable,
|
||||||
|
NotFoundException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { Children, StatutEnfantType } from 'src/entities/children.entity';
|
||||||
|
import { Parents } from 'src/entities/parents.entity';
|
||||||
|
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||||
|
import { RoleType, Users } from 'src/entities/users.entity';
|
||||||
|
import { CreateEnfantsDto } from './dto/create_enfants.dto';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class EnfantsService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(Children)
|
||||||
|
private readonly childrenRepository: Repository<Children>,
|
||||||
|
@InjectRepository(Parents)
|
||||||
|
private readonly parentsRepository: Repository<Parents>,
|
||||||
|
@InjectRepository(ParentsChildren)
|
||||||
|
private readonly parentsChildrenRepository: Repository<ParentsChildren>,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
// Création d’un enfant
|
||||||
|
async create(dto: CreateEnfantsDto, currentUser: Users): Promise<Children> {
|
||||||
|
const parent = await this.parentsRepository.findOne({
|
||||||
|
where: { user_id: currentUser.id },
|
||||||
|
});
|
||||||
|
if (!parent) throw new NotFoundException('Parent introuvable');
|
||||||
|
|
||||||
|
// Vérif métier simple
|
||||||
|
if (dto.status !== StatutEnfantType.A_NAITRE && !dto.birth_date) {
|
||||||
|
throw new BadRequestException('Un enfant actif doit avoir une date de naissance');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérif doublon éventuel (ex: même prénom + date de naissance pour ce parent)
|
||||||
|
const exist = await this.childrenRepository.findOne({
|
||||||
|
where: {
|
||||||
|
first_name: dto.first_name,
|
||||||
|
last_name: dto.last_name,
|
||||||
|
birth_date: dto.birth_date ? new Date(dto.birth_date) : undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (exist) throw new ConflictException('Cet enfant existe déjà');
|
||||||
|
|
||||||
|
// Création
|
||||||
|
const child = this.childrenRepository.create(dto);
|
||||||
|
await this.childrenRepository.save(child);
|
||||||
|
|
||||||
|
// Lien parent-enfant
|
||||||
|
const parentLink = this.parentsChildrenRepository.create({
|
||||||
|
parentId: parent.user_id,
|
||||||
|
enfantId: child.id,
|
||||||
|
});
|
||||||
|
await this.parentsChildrenRepository.save(parentLink);
|
||||||
|
|
||||||
|
return this.findOne(child.id, currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Liste des enfants
|
||||||
|
async findAll(): Promise<Children[]> {
|
||||||
|
return this.childrenRepository.find({
|
||||||
|
relations: ['parentLinks'],
|
||||||
|
order: { last_name: 'ASC', first_name: 'ASC' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer un enfant par id
|
||||||
|
async findOne(id: string, currentUser: Users): Promise<Children> {
|
||||||
|
const child = await this.childrenRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
relations: ['parentLinks'],
|
||||||
|
});
|
||||||
|
if (!child) throw new NotFoundException('Enfant introuvable');
|
||||||
|
|
||||||
|
switch (currentUser.role) {
|
||||||
|
case RoleType.PARENT:
|
||||||
|
if (!child.parentLinks.some(link => link.parentId === currentUser.id)) {
|
||||||
|
throw new ForbiddenException('Cet enfant ne vous appartient pas');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RoleType.ADMINISTRATEUR:
|
||||||
|
case RoleType.SUPER_ADMIN:
|
||||||
|
case RoleType.GESTIONNAIRE:
|
||||||
|
// accès complet
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new ForbiddenException('Accès interdit');
|
||||||
|
}
|
||||||
|
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Mise à jour
|
||||||
|
async update(id: string, dto: Partial<CreateEnfantsDto>, currentUser: Users): Promise<Children> {
|
||||||
|
const child = await this.childrenRepository.findOne({ where: { id } });
|
||||||
|
if (!child) throw new NotFoundException('Enfant introuvable');
|
||||||
|
|
||||||
|
await this.childrenRepository.update(id, dto);
|
||||||
|
return this.findOne(id, currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suppression
|
||||||
|
async remove(id: string): Promise<void> {
|
||||||
|
await this.childrenRepository.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import {
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Body,
|
|
||||||
Patch,
|
|
||||||
Param,
|
|
||||||
Delete,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { GestionnairesService } from './gestionnaires.service';
|
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
|
||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
|
||||||
import { UpdateGestionnaireDto } from '../user/dto/update_gestionnaire.dto';
|
|
||||||
import { CreateGestionnaireDto } from '../user/dto/create_gestionnaire.dto';
|
|
||||||
|
|
||||||
@Controller('gestionnaires')
|
|
||||||
export class GestionnairesController {
|
|
||||||
constructor(private readonly gestionnairesService: GestionnairesService) { }
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@Post()
|
|
||||||
create(@Body() dto: CreateGestionnaireDto): Promise<Users> {
|
|
||||||
return this.gestionnairesService.create(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Get()
|
|
||||||
getAll(): Promise<Users[]> {
|
|
||||||
return this.gestionnairesService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
|
||||||
@Get(':id')
|
|
||||||
findOne(@Param('id') id: string): Promise<Users> {
|
|
||||||
return this.gestionnairesService.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@Patch(':id')
|
|
||||||
update(
|
|
||||||
@Param('id') id: string,
|
|
||||||
@Body() dto: UpdateGestionnaireDto,
|
|
||||||
): Promise<Users | null> {
|
|
||||||
return this.gestionnairesService.update(id, dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@Delete(':id')
|
|
||||||
remove(@Param('id') id: string): Promise<void> {
|
|
||||||
return this.gestionnairesService.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,16 +22,17 @@ export class ParentsController {
|
|||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@Get()
|
@Get()
|
||||||
@ApiResponse({ status: 200, description: 'Liste des parents' })
|
@ApiResponse({ status: 200, type: [Parents], description: 'Liste des parents' })
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé : Réservé aux super_admins' })
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
||||||
getAll(): Promise<Parents[]> {
|
getAll(): Promise<Parents[]> {
|
||||||
return this.parentsService.findAll();
|
return this.parentsService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiResponse({ status: 200, description: 'Détails du parent par ID utilisateur' })
|
@ApiResponse({ status: 200, type: Parents, description: 'Détails du parent par ID utilisateur' })
|
||||||
@ApiResponse({ status: 404, description: 'Parent non trouvé' })
|
@ApiResponse({ status: 404, description: 'Parent non trouvé' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
||||||
getOne(@Param('id') user_id: string): Promise<Parents> {
|
getOne(@Param('id') user_id: string): Promise<Parents> {
|
||||||
return this.parentsService.findOne(user_id);
|
return this.parentsService.findOne(user_id);
|
||||||
}
|
}
|
||||||
@@ -39,7 +40,8 @@ export class ParentsController {
|
|||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@Post()
|
@Post()
|
||||||
@ApiBody({ type: CreateParentDto })
|
@ApiBody({ type: CreateParentDto })
|
||||||
@ApiResponse({ status: 201, description: 'Parent créé avec succès' })
|
@ApiResponse({ status: 201, type: Parents, description: 'Parent créé avec succès' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
||||||
create(@Body() dto: CreateParentDto): Promise<Parents> {
|
create(@Body() dto: CreateParentDto): Promise<Parents> {
|
||||||
return this.parentsService.create(dto);
|
return this.parentsService.create(dto);
|
||||||
}
|
}
|
||||||
@@ -47,18 +49,10 @@ export class ParentsController {
|
|||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@ApiBody({ type: UpdateParentsDto })
|
@ApiBody({ type: UpdateParentsDto })
|
||||||
@ApiResponse({ status: 200, description: 'Parent mis à jour avec succès' })
|
@ApiResponse({ status: 200, type: Parents, description: 'Parent mis à jour avec succès' })
|
||||||
@ApiResponse({ status: 404, description: 'Parent introuvable' })
|
@ApiResponse({ status: 404, description: 'Parent introuvable' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateParentsDto): Promise<Parents> {
|
update(@Param('id') id: string, @Body() dto: UpdateParentsDto): Promise<Parents> {
|
||||||
return this.parentsService.update(id, dto);
|
return this.parentsService.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Delete(':id')
|
|
||||||
@ApiResponse({ status: 200, description: 'Parent supprimé avec succès' })
|
|
||||||
@ApiResponse({ status: 404, description: 'Parent introuvable' })
|
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
|
||||||
remove(@Param('id') id: string): Promise<void> {
|
|
||||||
return this.parentsService.remove(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,8 @@ import { Users } from 'src/entities/users.entity';
|
|||||||
imports: [TypeOrmModule.forFeature([Parents, Users])],
|
imports: [TypeOrmModule.forFeature([Parents, Users])],
|
||||||
controllers: [ParentsController],
|
controllers: [ParentsController],
|
||||||
providers: [ParentsService],
|
providers: [ParentsService],
|
||||||
|
exports: [ParentsService,
|
||||||
|
TypeOrmModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class ParentsModule {}
|
export class ParentsModule { }
|
||||||
@@ -71,9 +71,4 @@ export class ParentsService {
|
|||||||
await this.parentsRepository.update(id, dto);
|
await this.parentsRepository.update(id, dto);
|
||||||
return this.findOne(id);
|
return this.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppression
|
|
||||||
async remove(id: string): Promise<void> {
|
|
||||||
await this.parentsRepository.delete(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,56 @@
|
|||||||
import { OmitType } from "@nestjs/swagger";
|
import { OmitType } from "@nestjs/swagger";
|
||||||
|
import { IsBoolean, IsDateString, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID, Length, Matches, Max, Min } from "class-validator";
|
||||||
import { CreateUserDto } from "./create_user.dto";
|
import { CreateUserDto } from "./create_user.dto";
|
||||||
import { IsBoolean, IsDateString, IsInt, IsOptional, IsString, IsUUID, Length, Matches, Max, Min } from "class-validator";
|
|
||||||
|
|
||||||
export class CreateAssistanteDto extends OmitType(CreateUserDto, ['role'] as const) {
|
export class CreateAssistanteDto extends OmitType(CreateUserDto, ['role', 'photo_url', 'consentement_photo'] as const) {
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
user_id?: string;
|
user_id?: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
@Length(1, 50)
|
@Length(1, 50)
|
||||||
numero_agrement?: string;
|
approval_number: string;
|
||||||
|
|
||||||
@IsDateString()
|
|
||||||
@IsOptional()
|
|
||||||
date_naissance?: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
@Length(1, 100)
|
|
||||||
ville_naissance?: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
@Length(2, 2)
|
|
||||||
pays_naissance?: string;
|
|
||||||
|
|
||||||
@Matches(/^\d{15}$/)
|
@Matches(/^\d{15}$/)
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
nir_chiffre?: string;
|
nir: string;
|
||||||
|
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@Min(1)
|
@Min(1)
|
||||||
@Max(10)
|
@Max(10)
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
nb_max_enfants?: number;
|
max_children: number;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
@IsString()
|
||||||
biographie?: string;
|
@IsNotEmpty()
|
||||||
|
photo_url: string;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
disponible?: boolean;
|
@IsNotEmpty()
|
||||||
|
consentement_photo: boolean;
|
||||||
|
|
||||||
|
@IsDateString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
agreement_date: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@Length(1, 100)
|
||||||
|
residence_city: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
biography?: string;
|
||||||
@Length(1, 100)
|
|
||||||
ville_residence?: string;
|
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
available?: boolean;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
years_experience?: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
specialty?: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
places_available?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import { OmitType } from "@nestjs/swagger";
|
import { OmitType } from "@nestjs/swagger";
|
||||||
import { CreateUserDto } from "./create_user.dto";
|
import { CreateUserDto } from "./create_user.dto";
|
||||||
import { IsNotEmpty, IsOptional, IsUUID } from "class-validator";
|
import { IsNotEmpty, IsOptional, IsString, IsUUID } from "class-validator";
|
||||||
|
|
||||||
export class CreateParentDto extends OmitType(CreateUserDto, ['role'] as const) {
|
export class CreateParentDto extends OmitType(CreateUserDto, ['role', 'photo_url'] as const) {
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
@IsOptional()
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
user_id?: string;
|
user_id: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
co_parent_id?: string;
|
co_parent_id?: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
photo_url: string;
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
MinLength,
|
MinLength,
|
||||||
MaxLength,
|
MaxLength,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { RoleType, GenreType, StatutUtilisateurType } from 'src/entities/users.entity';
|
import { RoleType, GenreType, StatutUtilisateurType, SituationFamilialeType } from 'src/entities/users.entity';
|
||||||
|
|
||||||
export class CreateUserDto {
|
export class CreateUserDto {
|
||||||
@ApiProperty({ example: 'sosso.test@example.com' })
|
@ApiProperty({ example: 'sosso.test@example.com' })
|
||||||
@@ -18,27 +18,28 @@ export class CreateUserDto {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
@ApiProperty({ minLength: 6 })
|
@ApiProperty({ minLength: 6, example: 'Mon_motdepasse_fort_1234?' })
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
@MinLength(6)
|
@MinLength(6)
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'Julien' })
|
@ApiProperty({ example: 'Julien' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
@MaxLength(100)
|
@MaxLength(100)
|
||||||
first_name?: string;
|
prenom: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'Dupont' })
|
@ApiProperty({ example: 'Dupont' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
@MaxLength(100)
|
@MaxLength(100)
|
||||||
last_name?: string;
|
nom: string;
|
||||||
|
|
||||||
@ApiProperty({ enum: GenreType, required: false, default: GenreType.AUTRE })
|
@ApiProperty({ enum: GenreType, required: false, default: GenreType.AUTRE })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(GenreType)
|
@IsEnum(GenreType)
|
||||||
gender?: GenreType = GenreType.AUTRE;
|
genre?: GenreType = GenreType.AUTRE;
|
||||||
|
|
||||||
@ApiProperty({ enum: RoleType })
|
@ApiProperty({ enum: RoleType })
|
||||||
@IsEnum(RoleType)
|
@IsEnum(RoleType)
|
||||||
@@ -47,31 +48,35 @@ export class CreateUserDto {
|
|||||||
@ApiProperty({ enum: StatutUtilisateurType, required: false, default: StatutUtilisateurType.EN_ATTENTE })
|
@ApiProperty({ enum: StatutUtilisateurType, required: false, default: StatutUtilisateurType.EN_ATTENTE })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(StatutUtilisateurType)
|
@IsEnum(StatutUtilisateurType)
|
||||||
status?: StatutUtilisateurType = StatutUtilisateurType.EN_ATTENTE;
|
statut?: StatutUtilisateurType = StatutUtilisateurType.EN_ATTENTE;
|
||||||
|
|
||||||
|
@ApiProperty({ example: SituationFamilialeType.MARIE, required: false, enum: SituationFamilialeType, default: SituationFamilialeType.MARIE})
|
||||||
|
@IsOptional()
|
||||||
|
@IsEnum(SituationFamilialeType)
|
||||||
|
situation_familiale?: SituationFamilialeType;
|
||||||
|
|
||||||
@ApiProperty({ example: '+33123456789' })
|
@ApiProperty({ example: '+33123456789' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
@MaxLength(20)
|
@MaxLength(20)
|
||||||
phone?: string;
|
telephone: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'Paris', required: false })
|
@ApiProperty({ example: 'Paris', required: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@MaxLength(150)
|
@MaxLength(150)
|
||||||
city?: string;
|
ville?: string;
|
||||||
|
|
||||||
@ApiProperty({ example: '75000', required: false })
|
@ApiProperty({ example: '75000', required: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@MaxLength(10)
|
@MaxLength(10)
|
||||||
postal_code?: string;
|
code_postal?: string;
|
||||||
|
|
||||||
|
|
||||||
@ApiProperty({ example: '10 rue de la paix, 75000 Paris' })
|
@ApiProperty({ example: '10 rue de la paix, 75000 Paris' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
address?: string;
|
adresse: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'https://example.com/photo.jpg', required: false })
|
@ApiProperty({ example: 'https://example.com/photo.jpg', required: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -81,15 +86,20 @@ export class CreateUserDto {
|
|||||||
@ApiProperty({ default: false })
|
@ApiProperty({ default: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
consent_photo?: boolean = false;
|
consentement_photo?: boolean = false;
|
||||||
|
|
||||||
@ApiProperty({ required: false })
|
@ApiProperty({ required: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsDateString({}, { message: 'consent_photo_at doit être une date ISO valide' })
|
@IsDateString({}, { message: 'date_consentement_photo doit être une date ISO valide' })
|
||||||
consent_photo_at?: string | null;
|
date_consentement_photo?: string | null;
|
||||||
|
|
||||||
@ApiProperty({ default: false })
|
@ApiProperty({ default: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
must_change_password?: boolean = false;
|
changement_mdp_obligatoire?: boolean = false;
|
||||||
|
|
||||||
|
@ApiProperty({ example: true })
|
||||||
|
@IsBoolean()
|
||||||
|
@IsNotEmpty()
|
||||||
|
cguAccepted: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Body,
|
||||||
|
Patch,
|
||||||
|
Param,
|
||||||
|
Delete,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { GestionnairesService } from './gestionnaires.service';
|
||||||
|
import { RoleType, Users } from 'src/entities/users.entity';
|
||||||
|
import { Roles } from 'src/common/decorators/roles.decorator';
|
||||||
|
import { UpdateGestionnaireDto } from '../dto/update_gestionnaire.dto';
|
||||||
|
import { CreateGestionnaireDto } from '../dto/create_gestionnaire.dto';
|
||||||
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
|
|
||||||
|
|
||||||
|
@ApiTags('Gestionnaires')
|
||||||
|
@ApiBearerAuth('access-token')
|
||||||
|
@UseGuards(AuthGuard, RolesGuard)
|
||||||
|
@Controller('gestionnaires')
|
||||||
|
export class GestionnairesController {
|
||||||
|
constructor(private readonly gestionnairesService: GestionnairesService) { }
|
||||||
|
|
||||||
|
@Roles(RoleType.SUPER_ADMIN)
|
||||||
|
@ApiResponse({ status: 201, description: 'Le gestionnaire a été créé avec succès.', type: Users })
|
||||||
|
@ApiResponse({ status: 409, description: 'Conflit. L\'email est déjà utilisé.' })
|
||||||
|
@ApiOperation({ summary: 'Création d\'un gestionnaire' })
|
||||||
|
@ApiBody({ type: CreateGestionnaireDto })
|
||||||
|
@Post()
|
||||||
|
create(@Body() dto: CreateGestionnaireDto): Promise<Users> {
|
||||||
|
return this.gestionnairesService.create(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
|
@ApiOperation({ summary: 'Liste des gestionnaires' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Liste des gestionnaires : ', type: [Users] })
|
||||||
|
@Get()
|
||||||
|
getAll(): Promise<Users[]> {
|
||||||
|
return this.gestionnairesService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(RoleType.GESTIONNAIRE, RoleType.SUPER_ADMIN)
|
||||||
|
@ApiOperation({ summary: 'Récupérer un gestionnaire par ID' })
|
||||||
|
@ApiResponse({ status: 400, description: 'ID invalide' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
||||||
|
@ApiResponse({ status: 401, description: 'Non authentifié' })
|
||||||
|
@ApiParam({ name: 'id', description: 'ID du gestionnaire' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Gestionnaire trouvé', type: Users })
|
||||||
|
@ApiResponse({ status: 404, description: 'Gestionnaire non trouvé' })
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string): Promise<Users> {
|
||||||
|
return this.gestionnairesService.findOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Roles(RoleType.SUPER_ADMIN)
|
||||||
|
@ApiOperation({ summary: 'Mettre à jour un gestionnaire' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Le gestionnaire a été mis à jour avec succès.', type: Users })
|
||||||
|
@ApiResponse({ status: 404, description: 'Gestionnaire non trouvé' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
||||||
|
@ApiResponse({ status: 401, description: 'Non authentifié' })
|
||||||
|
@ApiParam({ name: 'id', description: 'ID du gestionnaire' })
|
||||||
|
@Patch(':id')
|
||||||
|
update(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() dto: UpdateGestionnaireDto,
|
||||||
|
): Promise<Users | null> {
|
||||||
|
return this.gestionnairesService.update(id, dto);
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
-28
@@ -1,14 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
ConflictException,
|
ConflictException,
|
||||||
ForbiddenException,
|
|
||||||
Injectable,
|
Injectable,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
import { RoleType, Users } from 'src/entities/users.entity';
|
||||||
import { CreateGestionnaireDto } from '../user/dto/create_gestionnaire.dto';
|
import { CreateGestionnaireDto } from '../dto/create_gestionnaire.dto';
|
||||||
import { UpdateGestionnaireDto } from '../user/dto/update_gestionnaire.dto';
|
import { UpdateGestionnaireDto } from '../dto/update_gestionnaire.dto';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -24,24 +23,25 @@ export class GestionnairesService {
|
|||||||
if (exist) throw new ConflictException('Email déjà utilisé');
|
if (exist) throw new ConflictException('Email déjà utilisé');
|
||||||
|
|
||||||
const salt = await bcrypt.genSalt();
|
const salt = await bcrypt.genSalt();
|
||||||
const password_hash = await bcrypt.hash(dto.password, salt);
|
const hashedPassword = await bcrypt.hash(dto.password, salt);
|
||||||
|
|
||||||
const entity = this.gestionnaireRepository.create({
|
const entity = this.gestionnaireRepository.create({
|
||||||
email: dto.email,
|
email: dto.email,
|
||||||
password_hash,
|
password: hashedPassword,
|
||||||
first_name: dto.first_name,
|
prenom: dto.prenom,
|
||||||
last_name: dto.last_name,
|
nom: dto.nom,
|
||||||
gender: dto.gender,
|
genre: dto.genre,
|
||||||
status: dto.status,
|
statut: dto.statut,
|
||||||
phone: dto.phone,
|
telephone: dto.telephone,
|
||||||
address: dto.address,
|
adresse: dto.adresse,
|
||||||
photo_url: dto.photo_url,
|
photo_url: dto.photo_url,
|
||||||
consent_photo: dto.consent_photo ?? false,
|
consentement_photo: dto.consentement_photo ?? false,
|
||||||
consent_photo_at: dto.consent_photo_at ? new Date(dto.consent_photo_at) : undefined,
|
date_consentement_photo: dto.date_consentement_photo
|
||||||
must_change_password: dto.must_change_password ?? false,
|
? new Date(dto.date_consentement_photo)
|
||||||
|
: undefined,
|
||||||
|
changement_mdp_obligatoire: dto.changement_mdp_obligatoire ?? false,
|
||||||
role: RoleType.GESTIONNAIRE,
|
role: RoleType.GESTIONNAIRE,
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.gestionnaireRepository.save(entity);
|
return this.gestionnaireRepository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,29 +60,28 @@ export class GestionnairesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mise à jour d’un gestionnaire
|
// Mise à jour d’un gestionnaire
|
||||||
async update(id: string, dto: UpdateGestionnaireDto): Promise<Users | null> {
|
async update(id: string, dto: UpdateGestionnaireDto): Promise<Users> {
|
||||||
const gestionnaire = await this.findOne(id);
|
const gestionnaire = await this.findOne(id);
|
||||||
if (!gestionnaire) throw new NotFoundException('Gestionnaire introuvable');
|
|
||||||
|
|
||||||
if (dto.password) {
|
if (dto.password) {
|
||||||
const salt = await bcrypt.genSalt();
|
const salt = await bcrypt.genSalt();
|
||||||
gestionnaire.password_hash = await bcrypt.hash(dto.password, salt);
|
gestionnaire.password = await bcrypt.hash(dto.password, salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dto.consent_photo_at !== undefined) {
|
if (dto.date_consentement_photo !== undefined) {
|
||||||
gestionnaire.consent_photo_at = dto.consent_photo_at
|
gestionnaire.date_consentement_photo = dto.date_consentement_photo
|
||||||
? new Date(dto.consent_photo_at)
|
? new Date(dto.date_consentement_photo)
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(gestionnaire, dto);
|
const { password, date_consentement_photo, ...rest } = dto;
|
||||||
|
Object.entries(rest).forEach(([key, value]) => {
|
||||||
|
if (value !== undefined) {
|
||||||
|
(gestionnaire as any)[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return this.gestionnaireRepository.save(gestionnaire);
|
return this.gestionnaireRepository.save(gestionnaire);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppression d’un gestionnaire
|
|
||||||
async remove(id: string): Promise<void> {
|
|
||||||
const gestionnaire = await this.findOne(id);
|
|
||||||
if (!gestionnaire) throw new NotFoundException('Gestionnaire introuvable');
|
|
||||||
await this.gestionnaireRepository.delete(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
import { Roles } from 'src/common/decorators/roles.decorator';
|
||||||
import { User } from 'src/common/decorators/user.decorator';
|
import { User } from 'src/common/decorators/user.decorator';
|
||||||
@@ -13,7 +13,7 @@ import { UpdateUserDto } from './dto/update_user.dto';
|
|||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@Controller('users')
|
@Controller('users')
|
||||||
export class UserController {
|
export class UserController {
|
||||||
constructor(private readonly userService: UserService) {}
|
constructor(private readonly userService: UserService) { }
|
||||||
|
|
||||||
// Création d'un utilisateur (réservée aux super admins)
|
// Création d'un utilisateur (réservée aux super admins)
|
||||||
@Post()
|
@Post()
|
||||||
@@ -56,12 +56,39 @@ export class UserController {
|
|||||||
return this.userService.updateUser(id, dto, currentUser);
|
return this.userService.updateUser(id, dto, currentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un utilisateur (super_admin et gestionnaire)
|
@Patch(':id/valider')
|
||||||
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||||
|
@ApiOperation({ summary: 'Valider un compte utilisateur' })
|
||||||
|
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
||||||
|
@ApiResponse({ status: 400, description: 'ID invalide' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Compte validé avec succès' })
|
||||||
|
validate(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@User() currentUser: Users,
|
||||||
|
@Body('comment') comment?: string,
|
||||||
|
) {
|
||||||
|
return this.userService.validateUser(id, currentUser, comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id/suspendre')
|
||||||
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||||
|
@ApiOperation({ summary: 'Suspendre un compte utilisateur' })
|
||||||
|
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
||||||
|
suspend(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@User() currentUser: Users,
|
||||||
|
@Body('comment') comment?: string,
|
||||||
|
) {
|
||||||
|
return this.userService.suspendUser(id, currentUser, comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprimer un utilisateur (super_admin uniquement)
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN)
|
||||||
@ApiOperation({ summary: 'Supprimer un utilisateur' })
|
@ApiOperation({ summary: 'Supprimer un utilisateur' })
|
||||||
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string, @User() currentUser: Users) {
|
||||||
return this.userService.remove(id);
|
return this.userService.remove(id, currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,22 @@ import { UserService } from './user.service';
|
|||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Users } from 'src/entities/users.entity';
|
import { Users } from 'src/entities/users.entity';
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
import { Validation } from 'src/entities/validations.entity';
|
||||||
|
import { ParentsModule } from '../parents/parents.module';
|
||||||
|
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||||
|
import { AssistantesMaternellesModule } from '../assistantes_maternelles/assistantes_maternelles.module';
|
||||||
|
import { Parents } from 'src/entities/parents.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Users]),
|
imports: [TypeOrmModule.forFeature(
|
||||||
forwardRef(() => AuthModule),
|
[
|
||||||
|
Users,
|
||||||
|
Validation,
|
||||||
|
Parents,
|
||||||
|
AssistanteMaternelle,
|
||||||
|
]), forwardRef(() => AuthModule),
|
||||||
|
ParentsModule,
|
||||||
|
AssistantesMaternellesModule,
|
||||||
],
|
],
|
||||||
controllers: [UserController],
|
controllers: [UserController],
|
||||||
providers: [UserService],
|
providers: [UserService],
|
||||||
|
|||||||
+156
-39
@@ -1,70 +1,119 @@
|
|||||||
import { ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
||||||
import { InjectRepository } from "@nestjs/typeorm";
|
import { InjectRepository } from "@nestjs/typeorm";
|
||||||
import { RoleType, Users } from "src/entities/users.entity";
|
import { RoleType, StatutUtilisateurType, Users } from "src/entities/users.entity";
|
||||||
import { Repository } from "typeorm";
|
import { In, Repository } from "typeorm";
|
||||||
import { CreateUserDto } from "./dto/create_user.dto";
|
import { CreateUserDto } from "./dto/create_user.dto";
|
||||||
import { UpdateUserDto } from "./dto/update_user.dto";
|
import { UpdateUserDto } from "./dto/update_user.dto";
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
|
import { StatutValidationType, Validation } from "src/entities/validations.entity";
|
||||||
|
import { Parents } from "src/entities/parents.entity";
|
||||||
|
import { AssistanteMaternelle } from "src/entities/assistantes_maternelles.entity";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Users)
|
@InjectRepository(Users)
|
||||||
private readonly usersRepository: Repository<Users>
|
private readonly usersRepository: Repository<Users>,
|
||||||
|
|
||||||
|
@InjectRepository(Validation)
|
||||||
|
private readonly validationRepository: Repository<Validation>,
|
||||||
|
|
||||||
|
@InjectRepository(Parents)
|
||||||
|
private readonly parentsRepository: Repository<Parents>,
|
||||||
|
|
||||||
|
@InjectRepository(AssistanteMaternelle)
|
||||||
|
private readonly assistantesRepository: Repository<AssistanteMaternelle>
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
// Création utilisateur
|
|
||||||
async createUser(dto: CreateUserDto, currentUser?: Users): Promise<Users> {
|
async createUser(dto: CreateUserDto, currentUser?: Users): Promise<Users> {
|
||||||
// Sécuriser le rôle
|
if (!dto.cguAccepted) {
|
||||||
if (!currentUser || currentUser.role !== RoleType.SUPER_ADMIN) {
|
throw new BadRequestException(
|
||||||
dto.role = RoleType.PARENT;
|
'Vous devez accepter les CGU et la Politique de confidentialité pour créer un compte.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nettoyage / validation consentement photo
|
const exist = await this.usersRepository.findOneBy({ email: dto.email });
|
||||||
|
if (exist) throw new BadRequestException('Email déjà utilisé');
|
||||||
|
|
||||||
|
const isSuperAdmin = currentUser?.role === RoleType.SUPER_ADMIN;
|
||||||
|
const isAdmin = currentUser?.role === RoleType.ADMINISTRATEUR;
|
||||||
|
|
||||||
|
let role: RoleType;
|
||||||
|
|
||||||
|
if (dto.role === RoleType.GESTIONNAIRE) {
|
||||||
|
if (!isAdmin && !isSuperAdmin) {
|
||||||
|
throw new ForbiddenException('Seuls les administrateurs peuvent créer un gestionnaire');
|
||||||
|
}
|
||||||
|
role = RoleType.GESTIONNAIRE;
|
||||||
|
} else if (dto.role === RoleType.ADMINISTRATEUR) {
|
||||||
|
if (!isAdmin && !isSuperAdmin) {
|
||||||
|
throw new ForbiddenException('Seuls les administrateurs peuvent créer un administrateur');
|
||||||
|
}
|
||||||
|
role = RoleType.ADMINISTRATEUR;
|
||||||
|
} else if (dto.role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
|
role = RoleType.ASSISTANTE_MATERNELLE;
|
||||||
|
if (!dto.photo_url) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'La photo de profil est obligatoire pour les assistantes maternelles.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
role = RoleType.PARENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statut = isSuperAdmin
|
||||||
|
? dto.statut ?? StatutUtilisateurType.EN_ATTENTE
|
||||||
|
: StatutUtilisateurType.EN_ATTENTE;
|
||||||
|
|
||||||
|
if (!dto.nom?.trim()) throw new BadRequestException('Nom est obligatoire.');
|
||||||
|
if (!dto.prenom?.trim()) throw new BadRequestException('Prénom est obligatoire.');
|
||||||
|
if (!dto.adresse?.trim()) throw new BadRequestException('Adresse est obligatoire.');
|
||||||
|
if (!dto.telephone?.trim()) throw new BadRequestException('Téléphone est obligatoire.');
|
||||||
|
|
||||||
let consentDate: Date | undefined;
|
let consentDate: Date | undefined;
|
||||||
if (dto.consent_photo && dto.consent_photo_at) {
|
if (dto.consentement_photo && dto.date_consentement_photo) {
|
||||||
const parsed = new Date(dto.consent_photo_at);
|
const parsed = new Date(dto.date_consentement_photo);
|
||||||
if (!isNaN(parsed.getTime())) {
|
if (!isNaN(parsed.getTime())) {
|
||||||
consentDate = parsed;
|
consentDate = parsed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash mot de passe
|
|
||||||
const salt = await bcrypt.genSalt();
|
const salt = await bcrypt.genSalt();
|
||||||
const password_hash = await bcrypt.hash(dto.password, salt);
|
const hashedPassword = await bcrypt.hash(dto.password, salt);
|
||||||
|
|
||||||
const entity = this.usersRepository.create({
|
const entity = this.usersRepository.create({
|
||||||
email: dto.email,
|
email: dto.email,
|
||||||
password_hash,
|
password: hashedPassword,
|
||||||
first_name: dto.first_name,
|
prenom: dto.prenom,
|
||||||
last_name: dto.last_name,
|
nom: dto.nom,
|
||||||
role: dto.role,
|
role,
|
||||||
status: dto.status,
|
statut,
|
||||||
gender: dto.gender,
|
genre: dto.genre,
|
||||||
phone: dto.phone,
|
telephone: dto.telephone,
|
||||||
address: dto.address,
|
ville: dto.ville,
|
||||||
|
code_postal: dto.code_postal,
|
||||||
|
adresse: dto.adresse,
|
||||||
photo_url: dto.photo_url,
|
photo_url: dto.photo_url,
|
||||||
consent_photo: dto.consent_photo ?? false,
|
consentement_photo: dto.consentement_photo ?? false,
|
||||||
consent_photo_at: consentDate,
|
date_consentement_photo: consentDate,
|
||||||
must_change_password: dto.must_change_password ?? false
|
changement_mdp_obligatoire:
|
||||||
|
role === RoleType.ADMINISTRATEUR || role === RoleType.GESTIONNAIRE
|
||||||
|
? true
|
||||||
|
: dto.changement_mdp_obligatoire ?? false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const saved = await this.usersRepository.save(entity);
|
const saved = await this.usersRepository.save(entity);
|
||||||
return this.findOne(saved.id);
|
return this.findOne(saved.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Trouver tous les utilisateurs
|
|
||||||
async findAll(): Promise<Users[]> {
|
async findAll(): Promise<Users[]> {
|
||||||
return this.usersRepository.find();
|
return this.usersRepository.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Trouver utilisateur par condition
|
|
||||||
async findOneBy(where: Partial<Users>): Promise<Users | null> {
|
async findOneBy(where: Partial<Users>): Promise<Users | null> {
|
||||||
return this.usersRepository.findOne({ where });
|
return this.usersRepository.findOne({ where });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trouver utilisateur par ID
|
|
||||||
async findOne(id: string): Promise<Users> {
|
async findOne(id: string): Promise<Users> {
|
||||||
const user = await this.usersRepository.findOne({ where: { id } });
|
const user = await this.usersRepository.findOne({ where: { id } });
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -73,12 +122,10 @@ export class UserService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trouver utilisateur par email
|
|
||||||
async findByEmailOrNull(email: string): Promise<Users | null> {
|
async findByEmailOrNull(email: string): Promise<Users | null> {
|
||||||
return this.usersRepository.findOne({ where: { email } });
|
return this.usersRepository.findOne({ where: { email } });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour un utilisateur
|
|
||||||
async updateUser(id: string, dto: UpdateUserDto, currentUser: Users): Promise<Users> {
|
async updateUser(id: string, dto: UpdateUserDto, currentUser: Users): Promise<Users> {
|
||||||
const user = await this.findOne(id);
|
const user = await this.findOne(id);
|
||||||
|
|
||||||
@@ -87,30 +134,100 @@ export class UserService {
|
|||||||
throw new ForbiddenException('Accès réservé aux super admins');
|
throw new ForbiddenException('Accès réservé aux super admins');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empêcher de modifier le flag changement_mdp_obligatoire pour admin/gestionnaire
|
||||||
|
if (
|
||||||
|
(user.role === RoleType.ADMINISTRATEUR || user.role === RoleType.GESTIONNAIRE) &&
|
||||||
|
dto.changement_mdp_obligatoire === false
|
||||||
|
) {
|
||||||
|
throw new ForbiddenException(
|
||||||
|
'Impossible de désactiver l’obligation de changement de mot de passe pour ce rôle',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Gestion du mot de passe
|
// Gestion du mot de passe
|
||||||
if (dto.password) {
|
if (dto.password) {
|
||||||
const salt = await bcrypt.genSalt();
|
const salt = await bcrypt.genSalt();
|
||||||
user.password_hash = await bcrypt.hash(dto.password, salt);
|
user.password = await bcrypt.hash(dto.password, salt);
|
||||||
delete (dto as any).password;
|
delete (dto as any).password;
|
||||||
|
// Une fois le mot de passe changé, on peut lever l’obligation
|
||||||
|
user.changement_mdp_obligatoire = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversion de la date de consentement
|
// Conversion de la date de consentement
|
||||||
if (dto.consent_photo_at !== undefined) {
|
if (dto.date_consentement_photo !== undefined) {
|
||||||
user.consent_photo_at = dto.consent_photo_at
|
user.date_consentement_photo = dto.date_consentement_photo
|
||||||
? new Date(dto.consent_photo_at)
|
? new Date(dto.date_consentement_photo)
|
||||||
: undefined;
|
: undefined;
|
||||||
delete (dto as any).consent_photo_at;
|
delete (dto as any).date_consentement_photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(user, dto);
|
Object.assign(user, dto);
|
||||||
return this.usersRepository.save(user);
|
return this.usersRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un utilisateur
|
// Valider un compte utilisateur
|
||||||
async remove(id: string): Promise<void> {
|
async validateUser(user_id: string, currentUser: Users, comment?: string): Promise<Users> {
|
||||||
|
if (![RoleType.SUPER_ADMIN, RoleType.ADMINISTRATEUR, RoleType.GESTIONNAIRE].includes(currentUser.role)) {
|
||||||
|
throw new ForbiddenException('Accès réservé aux super admins, administrateurs et gestionnaires');
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await this.usersRepository.findOne({ where: { id: user_id } });
|
||||||
|
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
||||||
|
|
||||||
|
user.statut = StatutUtilisateurType.ACTIF;
|
||||||
|
const savedUser = await this.usersRepository.save(user);
|
||||||
|
if (user.role === RoleType.PARENT) {
|
||||||
|
const existParent = await this.parentsRepository.findOneBy({ user_id: user.id });
|
||||||
|
if (!existParent) {
|
||||||
|
const parentEntity = this.parentsRepository.create({ user_id: user.id, user });
|
||||||
|
await this.parentsRepository.save(parentEntity);
|
||||||
|
}
|
||||||
|
} else if (user.role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
|
const existAssistante = await this.assistantesRepository.findOneBy({ user_id: user.id });
|
||||||
|
if (!existAssistante) {
|
||||||
|
const assistanteEntity = this.assistantesRepository.create({ user_id: user.id, user });
|
||||||
|
await this.assistantesRepository.save(assistanteEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const validation = this.validationRepository.create({
|
||||||
|
user: savedUser,
|
||||||
|
type: 'validation_compte',
|
||||||
|
status: StatutValidationType.VALIDE,
|
||||||
|
validated_by: currentUser,
|
||||||
|
comment,
|
||||||
|
});
|
||||||
|
await this.validationRepository.save(validation);
|
||||||
|
return savedUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Mettre un compte en statut suspendu
|
||||||
|
async suspendUser(user_id: string, currentUser: Users, comment?: string): Promise<Users> {
|
||||||
|
if (![RoleType.SUPER_ADMIN, RoleType.ADMINISTRATEUR, RoleType.GESTIONNAIRE].includes(currentUser.role)) {
|
||||||
|
throw new ForbiddenException('Accès réservé aux super admins, administrateurs et gestionnaires');
|
||||||
|
}
|
||||||
|
const user = await this.usersRepository.findOne({ where: { id: user_id } });
|
||||||
|
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
||||||
|
user.statut = StatutUtilisateurType.SUSPENDU;
|
||||||
|
const savedUser = await this.usersRepository.save(user);
|
||||||
|
|
||||||
|
const suspend = this.validationRepository.create({
|
||||||
|
user: savedUser,
|
||||||
|
type: 'suspension_compte',
|
||||||
|
status: StatutValidationType.VALIDE,
|
||||||
|
validated_by: currentUser,
|
||||||
|
comment,
|
||||||
|
})
|
||||||
|
await this.validationRepository.save(suspend);
|
||||||
|
return savedUser;
|
||||||
|
}
|
||||||
|
async remove(id: string, currentUser: Users): Promise<void> {
|
||||||
|
if (currentUser.role !== RoleType.SUPER_ADMIN) {
|
||||||
|
throw new ForbiddenException('Accès réservé aux super admins');
|
||||||
|
}
|
||||||
const result = await this.usersRepository.delete(id);
|
const result = await this.usersRepository.delete(id);
|
||||||
if (result.affected === 0) {
|
if (result.affected === 0) {
|
||||||
throw new NotFoundException('Utilisateur introuvable');
|
throw new NotFoundException('Utilisateur introuvable');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+6
-2
@@ -2,6 +2,10 @@ import { Users } from 'src/entities/users.entity';
|
|||||||
|
|
||||||
declare module 'express-serve-static-core' {
|
declare module 'express-serve-static-core' {
|
||||||
interface Request {
|
interface Request {
|
||||||
user?: Users | any;
|
user?: Users & {
|
||||||
|
sub?: string;
|
||||||
|
email?: string;
|
||||||
|
role?: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user