Compare commits
No commits in common. "master" and "master" have entirely different histories.
23
.env.example
23
.env.example
@ -1,23 +0,0 @@
|
|||||||
# Fichier: .env.example
|
|
||||||
# Copier ce fichier vers .env et adapter les valeurs selon votre environnement
|
|
||||||
|
|
||||||
# Configuration de la base de données PostgreSQL
|
|
||||||
POSTGRES_HOST=postgres
|
|
||||||
POSTGRES_PORT=5432
|
|
||||||
POSTGRES_USER=admin
|
|
||||||
POSTGRES_PASSWORD=admin123
|
|
||||||
POSTGRES_DB=ptitpas_db
|
|
||||||
|
|
||||||
# Configuration PgAdmin (accessible sur http://localhost:8080)
|
|
||||||
PGADMIN_DEFAULT_EMAIL=admin@localhost
|
|
||||||
PGADMIN_DEFAULT_PASSWORD=admin123
|
|
||||||
|
|
||||||
# Configuration de l'API
|
|
||||||
API_PORT=3000
|
|
||||||
|
|
||||||
# Secrets pour l'authentification JWT
|
|
||||||
JWT_SECRET=dev-jwt-secret-key-change-me
|
|
||||||
JWT_EXPIRATION_TIME=7d
|
|
||||||
|
|
||||||
# Environnement
|
|
||||||
NODE_ENV=development
|
|
||||||
8
.gitignore
vendored
8
.gitignore
vendored
@ -54,11 +54,3 @@ 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
|
|
||||||
|
|
||||||
|
|
||||||
# Tests bdd
|
|
||||||
.vscode/
|
|
||||||
BDD.sql
|
|
||||||
migrations/
|
|
||||||
src/seed/
|
|
||||||
|
|||||||
39
Dockerfile
39
Dockerfile
@ -1,39 +0,0 @@
|
|||||||
FROM node:22-alpine AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copier les fichiers de configuration
|
|
||||||
COPY package*.json ./
|
|
||||||
COPY tsconfig*.json ./
|
|
||||||
COPY nest-cli.json ./
|
|
||||||
|
|
||||||
# Installer TOUTES les dépendances (dev + prod pour le build)
|
|
||||||
RUN npm install && npm cache clean --force
|
|
||||||
|
|
||||||
# Copier le code source
|
|
||||||
COPY src ./src
|
|
||||||
|
|
||||||
# Builder l'application
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# Stage production
|
|
||||||
FROM node:22-alpine AS production
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Installer seulement les dépendances de production
|
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install --only=production && npm cache clean --force
|
|
||||||
|
|
||||||
# Copier le build depuis le stage builder
|
|
||||||
COPY --from=builder /app/dist ./dist
|
|
||||||
|
|
||||||
# Créer un utilisateur non-root
|
|
||||||
RUN addgroup -g 1001 -S nodejs
|
|
||||||
RUN adduser -S nestjs -u 1001
|
|
||||||
|
|
||||||
USER nestjs
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
CMD ["node", "dist/main"]
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
# 🚀 Guide de développement local
|
|
||||||
|
|
||||||
## Prérequis
|
|
||||||
- Docker et Docker Compose installés
|
|
||||||
- Git
|
|
||||||
|
|
||||||
## 🏃♂️ Démarrage rapide
|
|
||||||
|
|
||||||
### 1. Cloner le projet
|
|
||||||
```bash
|
|
||||||
git clone <url-du-depot-backend>
|
|
||||||
cd ptitspas-backend
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Configuration de l'environnement
|
|
||||||
```bash
|
|
||||||
# Copier le fichier d'exemple
|
|
||||||
cp .env.example .env
|
|
||||||
|
|
||||||
# Optionnel : adapter les valeurs dans .env selon vos besoins
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Lancer l'application
|
|
||||||
```bash
|
|
||||||
# Démarrer tous les services (PostgreSQL + PgAdmin + Backend)
|
|
||||||
docker compose -f docker-compose.dev.yml up -d
|
|
||||||
|
|
||||||
# Voir les logs
|
|
||||||
docker compose -f docker-compose.dev.yml logs -f
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🌐 Accès aux services
|
|
||||||
|
|
||||||
- **Backend API** : http://localhost:3000
|
|
||||||
- **PgAdmin** : http://localhost:8080
|
|
||||||
- Email : admin@localhost
|
|
||||||
- Mot de passe : admin123
|
|
||||||
- **PostgreSQL** : localhost:5432
|
|
||||||
- Utilisateur : admin
|
|
||||||
- Mot de passe : admin123
|
|
||||||
- Base : ptitpas_db
|
|
||||||
|
|
||||||
## 🛠️ Commandes utiles
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Arrêter les services
|
|
||||||
docker compose -f docker-compose.dev.yml down
|
|
||||||
|
|
||||||
# Rebuild le backend après modification du Dockerfile
|
|
||||||
docker compose -f docker-compose.dev.yml up --build backend
|
|
||||||
|
|
||||||
# Voir l'état des services
|
|
||||||
docker compose -f docker-compose.dev.yml ps
|
|
||||||
|
|
||||||
# Accéder au container backend
|
|
||||||
docker exec -it ptitspas-backend-dev sh
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📝 Notes de développement
|
|
||||||
|
|
||||||
- Les modifications du code source sont automatiquement prises en compte (hot reload)
|
|
||||||
- Les données PostgreSQL sont persistantes via le volume `postgres_dev_data`
|
|
||||||
- Le fichier `.env` n'est pas versionné pour des raisons de sécurité
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
# Docker Compose pour développement local
|
|
||||||
# Usage: docker compose -f docker-compose.dev.yml up -d
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Base de données PostgreSQL
|
|
||||||
postgres:
|
|
||||||
image: postgres:17
|
|
||||||
container_name: ptitspas-postgres-dev
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
POSTGRES_USER: ${POSTGRES_USER:-admin}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin123}
|
|
||||||
POSTGRES_DB: ${POSTGRES_DB:-ptitpas_db}
|
|
||||||
ports:
|
|
||||||
- "5433:5432"
|
|
||||||
volumes:
|
|
||||||
# Si le fichier d'init existe dans le dépôt database
|
|
||||||
- ./migrations/01_init.sql:/docker-entrypoint-initdb.d/01_init.sql
|
|
||||||
- postgres_dev_data:/var/lib/postgresql/data
|
|
||||||
|
|
||||||
networks:
|
|
||||||
- ptitspas_dev
|
|
||||||
|
|
||||||
# Interface d'administration DB
|
|
||||||
pgadmin:
|
|
||||||
image: dpage/pgadmin4
|
|
||||||
container_name: ptitspas-pgadmin-dev
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@ptits-pas.fr}
|
|
||||||
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin123}
|
|
||||||
ports:
|
|
||||||
- "8080:80"
|
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
networks:
|
|
||||||
- ptitspas_dev
|
|
||||||
|
|
||||||
# Backend NestJS
|
|
||||||
backend:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
container_name: ptitspas-backend-dev
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
POSTGRES_HOST: ${POSTGRES_HOST:-postgres}
|
|
||||||
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
|
|
||||||
POSTGRES_USER: ${POSTGRES_USER:-admin}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin123}
|
|
||||||
POSTGRES_DB: ${POSTGRES_DB:-ptitpas_db}
|
|
||||||
API_PORT: ${API_PORT:-3000}
|
|
||||||
JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-key}
|
|
||||||
JWT_EXPIRATION_TIME: ${JWT_EXPIRATION_TIME:-7d}
|
|
||||||
NODE_ENV: ${NODE_ENV:-development}
|
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
volumes:
|
|
||||||
# Pour le hot reload en développement
|
|
||||||
- ./src:/app/src
|
|
||||||
- /app/node_modules
|
|
||||||
networks:
|
|
||||||
- ptitspas_dev
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
postgres_dev_data:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
ptitspas_dev:
|
|
||||||
driver: bridge
|
|
||||||
2089
package-lock.json
generated
2089
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@ -6,8 +6,6 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typeorm": "typeorm-ts-node-commonjs",
|
|
||||||
"migration:run": "npm run typeorm migration:run",
|
|
||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start": "nest start",
|
"start": "nest start",
|
||||||
@ -22,39 +20,21 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.1.6",
|
"@nestjs/common": "^11.0.1",
|
||||||
"@nestjs/config": "^4.0.2",
|
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/jwt": "^11.0.0",
|
|
||||||
"@nestjs/mapped-types": "^2.1.0",
|
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"@nestjs/swagger": "^11.2.0",
|
|
||||||
"@nestjs/typeorm": "^11.0.0",
|
|
||||||
"@sentry/nestjs": "^10.10.0",
|
|
||||||
"bcrypt": "^6.0.0",
|
|
||||||
"bcryptjs": "^3.0.2",
|
|
||||||
"class-transformer": "^0.5.1",
|
|
||||||
"class-validator": "^0.14.2",
|
|
||||||
"joi": "^18.0.0",
|
|
||||||
"mapped-types": "^0.0.1",
|
|
||||||
"passport-jwt": "^4.0.1",
|
|
||||||
"pg": "^8.16.3",
|
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1"
|
||||||
"swagger-ui-express": "^5.0.1",
|
|
||||||
"typeorm": "^0.3.26"
|
|
||||||
},
|
},
|
||||||
"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.10",
|
"@nestjs/cli": "^11.0.0",
|
||||||
"@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/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^22.10.7",
|
"@types/node": "^22.10.7",
|
||||||
"@types/passport-jwt": "^4.0.1",
|
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^9.18.0",
|
||||||
"eslint-config-prettier": "^10.0.1",
|
"eslint-config-prettier": "^10.0.1",
|
||||||
|
|||||||
@ -6,11 +6,6 @@ export class AppController {
|
|||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getOverView() {
|
|
||||||
return this.appService.getOverView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('hello')
|
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return this.appService.getHello();
|
return this.appService.getHello();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,67 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import appConfig from './config/app.config';
|
|
||||||
import databaseConfig from './config/database.config';
|
|
||||||
import jwtConfig from './config/jwt.config';
|
|
||||||
import { configValidationSchema } from './config/validation.schema';
|
|
||||||
import { UserModule } from './routes/user/user.module';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { APP_FILTER } from '@nestjs/core';
|
|
||||||
import { ParentsModule } from './routes/parents/parents.module';
|
|
||||||
import { AuthModule } from './routes/auth/auth.module';
|
|
||||||
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
|
|
||||||
import { AllExceptionsFilter } from './common/filters/all_exceptions.filters';
|
|
||||||
import { EnfantsModule } from './routes/enfants/enfants.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [],
|
||||||
ConfigModule.forRoot({
|
|
||||||
// Gestion dynamique des fichiers .env
|
|
||||||
envFilePath: [`.env.${process.env.NODE_ENV || 'development'}`, '.env'],
|
|
||||||
// envFilePath: '.env',
|
|
||||||
|
|
||||||
// Chargement de configurations typées
|
|
||||||
load: [appConfig, databaseConfig, jwtConfig],
|
|
||||||
|
|
||||||
isGlobal: true,
|
|
||||||
validationSchema: configValidationSchema,
|
|
||||||
}),
|
|
||||||
TypeOrmModule.forRootAsync({
|
|
||||||
imports: [ConfigModule,
|
|
||||||
],
|
|
||||||
inject: [ConfigService],
|
|
||||||
useFactory: (config: ConfigService) => ({
|
|
||||||
type: 'postgres',
|
|
||||||
host: config.get('database.host'),
|
|
||||||
port: config.get<number>('database.port'),
|
|
||||||
username: config.get('database.username'),
|
|
||||||
password: config.get('database.password'),
|
|
||||||
database: config.get('database.database'),
|
|
||||||
entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
|
||||||
synchronize: false,
|
|
||||||
migrations: [__dirname + '/migrations/**/*{.ts,.js}'],
|
|
||||||
logging: true,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
UserModule,
|
|
||||||
ParentsModule,
|
|
||||||
EnfantsModule,
|
|
||||||
AuthModule,
|
|
||||||
],
|
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [
|
providers: [AppService],
|
||||||
AppService,
|
|
||||||
{
|
|
||||||
provide: APP_FILTER,
|
|
||||||
useClass: SentryGlobalFilter
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: APP_FILTER,
|
|
||||||
useClass: AllExceptionsFilter,
|
|
||||||
}
|
|
||||||
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule {}
|
||||||
|
|||||||
@ -3,60 +3,6 @@ import { Injectable } from '@nestjs/common';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return 'Hello Test!!!';
|
return 'Hello World!';
|
||||||
}
|
|
||||||
|
|
||||||
getOverView() {
|
|
||||||
return {
|
|
||||||
name: "P'titsPas API",
|
|
||||||
version: "1.0",
|
|
||||||
description: "Documentation rapide des endpoints disponibles",
|
|
||||||
authentication: "JWT Bearer Token requis",
|
|
||||||
endpoints: [
|
|
||||||
{
|
|
||||||
method: "GET",
|
|
||||||
path: "/parents",
|
|
||||||
description: "Liste tous les parents",
|
|
||||||
roles: ["SUPER_ADMIN", "GESTIONNAIRE"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "GET",
|
|
||||||
path: "/parents/:id",
|
|
||||||
description: "Récupère un parent par ID utilisateur",
|
|
||||||
roles: ["SUPER_ADMIN", "GESTIONNAIRE"],
|
|
||||||
params: ["id (UUID)"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
path: "/parents",
|
|
||||||
description: "Crée un parent",
|
|
||||||
roles: ["SUPER_ADMIN", "GESTIONNAIRE"],
|
|
||||||
body: {
|
|
||||||
user_id: "UUID",
|
|
||||||
co_parent_id: "UUID (optionnel)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "PATCH",
|
|
||||||
path: "/parents/:id",
|
|
||||||
description: "Met à jour un parent",
|
|
||||||
roles: ["SUPER_ADMIN", "GESTIONNAIRE"],
|
|
||||||
params: ["id (UUID)"],
|
|
||||||
body: {
|
|
||||||
user_id: "UUID (optionnel)",
|
|
||||||
co_parent_id: "UUID (optionnel)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "DELETE",
|
|
||||||
path: "/parents/:id",
|
|
||||||
description: "Supprime un parent",
|
|
||||||
roles: ["SUPER_ADMIN"],
|
|
||||||
params: ["id (UUID)"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
docs: "/api/docs"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
import { SetMetadata } from "@nestjs/common";
|
|
||||||
|
|
||||||
export const IS_PUBLIC_KEY = 'isPublic';
|
|
||||||
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
import { SetMetadata } from "@nestjs/common";
|
|
||||||
|
|
||||||
export const Roles = (...roles: string[]) => SetMetadata("roles", roles);
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
import { createParamDecorator, ExecutionContext } from "@nestjs/common";
|
|
||||||
|
|
||||||
export const User = createParamDecorator((data: string | undefined, ctx: ExecutionContext) => {
|
|
||||||
const request = ctx.switchToHttp().getRequest();
|
|
||||||
const user = request.user;
|
|
||||||
return data ? user?.[data] : user;
|
|
||||||
});
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import { IsDateString, IsOptional } from "class-validator";
|
|
||||||
|
|
||||||
export class DateRangeQueryDto {
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
start?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
end?: string;
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
import { IsUUID } from "class-validator";
|
|
||||||
|
|
||||||
export class IdParamDto {
|
|
||||||
@IsUUID()
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import { IsOptional, IsPositive } from "class-validator";
|
|
||||||
|
|
||||||
export class PaginationQueryDto {
|
|
||||||
@IsOptional()
|
|
||||||
@IsPositive()
|
|
||||||
offset?: number;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsPositive()
|
|
||||||
limit?: number;
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { IsOptional, IsString, MinLength } from "class-validator";
|
|
||||||
|
|
||||||
export class SearchQueryDto {
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@MinLength(2)
|
|
||||||
q?: string;
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
import { ArgumentsHost, Catch, ExceptionFilter, HttpException, HttpStatus } from "@nestjs/common";
|
|
||||||
|
|
||||||
@Catch()
|
|
||||||
export class AllExceptionsFilter implements ExceptionFilter {
|
|
||||||
catch(exception: unknown, host: ArgumentsHost) {
|
|
||||||
const ctx = host.switchToHttp();
|
|
||||||
const response = ctx.getResponse();
|
|
||||||
const request = ctx.getRequest();
|
|
||||||
const status =
|
|
||||||
exception instanceof HttpException
|
|
||||||
? exception.getStatus()
|
|
||||||
: HttpStatus.INTERNAL_SERVER_ERROR;
|
|
||||||
|
|
||||||
const message =
|
|
||||||
exception instanceof HttpException
|
|
||||||
? exception.getResponse()
|
|
||||||
: { message: 'Internal server error' };
|
|
||||||
|
|
||||||
response.status(status).json({
|
|
||||||
success: false,
|
|
||||||
statusCode: status,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
path: request.url,
|
|
||||||
message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from "@nestjs/common";
|
|
||||||
import { Reflector } from "@nestjs/core";
|
|
||||||
import { JwtService } from "@nestjs/jwt";
|
|
||||||
import { Request } from 'express';
|
|
||||||
import { IS_PUBLIC_KEY } from "../decorators/public.decorator";
|
|
||||||
import { ConfigService } from "@nestjs/config";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AuthGuard implements CanActivate {
|
|
||||||
constructor(
|
|
||||||
private readonly jwtService: JwtService,
|
|
||||||
private readonly reflector: Reflector,
|
|
||||||
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;
|
|
||||||
|
|
||||||
const request = context.switchToHttp().getRequest<Request>();
|
|
||||||
if (request.path.startsWith('/api-docs')) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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,26 +0,0 @@
|
|||||||
import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common";
|
|
||||||
import { Reflector } from "@nestjs/core";
|
|
||||||
import { Observable } from "rxjs";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class RolesGuard implements CanActivate {
|
|
||||||
constructor(private readonly reflector: Reflector) {}
|
|
||||||
|
|
||||||
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
|
||||||
const requiredRoles = this.reflector.getAllAndOverride<string[]>('roles', [
|
|
||||||
context.getHandler(),
|
|
||||||
context.getClass(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!requiredRoles || requiredRoles.length === 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const request = context.switchToHttp().getRequest();
|
|
||||||
const user = request.user;
|
|
||||||
if (!user || !user.role) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return requiredRoles.includes(user.role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from "@nestjs/common";
|
|
||||||
import { map, Observable, timestamp } from "rxjs";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class TransformInterceptor implements NestInterceptor {
|
|
||||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
|
||||||
return next.handle().pipe(
|
|
||||||
map((data) => ({
|
|
||||||
success: true,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
data
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
import { registerAs } from '@nestjs/config';
|
|
||||||
|
|
||||||
export default registerAs('', () => ({
|
|
||||||
port: process.env.PORT,
|
|
||||||
env: process.env.NODE_ENV,
|
|
||||||
}));
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
import { registerAs } from '@nestjs/config';
|
|
||||||
|
|
||||||
export default registerAs('database', () => ({
|
|
||||||
host: process.env.POSTGRES_HOST,
|
|
||||||
port: process.env.POSTGRES_PORT,
|
|
||||||
username: process.env.POSTGRES_USER,
|
|
||||||
password: process.env.POSTGRES_PASSWORD,
|
|
||||||
database: process.env.POSTGRES_DB,
|
|
||||||
}));
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { registerAs } from '@nestjs/config';
|
|
||||||
|
|
||||||
export default registerAs('jwt', () => ({
|
|
||||||
accessSecret: process.env.JWT_ACCESS_SECRET,
|
|
||||||
accessExpiresIn: process.env.JWT_ACCESS_EXPIRES,
|
|
||||||
refreshSecret: process.env.JWT_REFRESH_SECRET,
|
|
||||||
refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES,
|
|
||||||
}));
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
import * as Joi from 'joi';
|
|
||||||
|
|
||||||
export const configValidationSchema = Joi.object({
|
|
||||||
NODE_ENV: Joi.string()
|
|
||||||
.valid('development', 'production', 'test')
|
|
||||||
.default('development'),
|
|
||||||
PORT: Joi.number().optional(),
|
|
||||||
|
|
||||||
// Base de données
|
|
||||||
POSTGRES_HOST: Joi.string().required(),
|
|
||||||
POSTGRES_PORT: Joi.number().required(),
|
|
||||||
POSTGRES_USER: Joi.string().required(),
|
|
||||||
POSTGRES_PASSWORD: Joi.string().required(),
|
|
||||||
POSTGRES_DB: Joi.string().required(),
|
|
||||||
|
|
||||||
// JWT
|
|
||||||
JWT_ACCESS_SECRET: Joi.string().required(),
|
|
||||||
JWT_ACCESS_EXPIRES: Joi.string().required(),
|
|
||||||
JWT_REFRESH_SECRET: Joi.string().required(),
|
|
||||||
JWT_REFRESH_EXPIRES: Joi.string().required(),
|
|
||||||
});
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
import { Entity, PrimaryColumn, Column, OneToOne, JoinColumn } from 'typeorm';
|
|
||||||
import { Users } from './users.entity';
|
|
||||||
|
|
||||||
@Entity('assistantes_maternelles')
|
|
||||||
export class AssistanteMaternelle {
|
|
||||||
// PK = FK vers utilisateurs.id
|
|
||||||
@PrimaryColumn('uuid', { name: 'id_utilisateur' })
|
|
||||||
user_id: string;
|
|
||||||
|
|
||||||
@OneToOne(() => Users, (user) => user.assistanteMaternelle, {
|
|
||||||
onDelete: 'CASCADE',
|
|
||||||
})
|
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
|
||||||
user: Users;
|
|
||||||
|
|
||||||
@Column({ name: 'numero_agrement', length: 50, nullable: true })
|
|
||||||
approval_number?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'nir_chiffre', length: 15, nullable: true })
|
|
||||||
nir?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'nb_max_enfants', type: 'int', nullable: true })
|
|
||||||
max_children?: number;
|
|
||||||
|
|
||||||
@Column({ name: 'biographie', type: 'text', nullable: true })
|
|
||||||
biography?: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
name: 'disponible',
|
|
||||||
type: 'boolean',
|
|
||||||
default: true,
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
available?: boolean;
|
|
||||||
|
|
||||||
@Column({ name: 'ville_residence', length: 100, nullable: true })
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
|
||||||
import { Contrat } from "./contrats.entity";
|
|
||||||
import { Users } from "./users.entity";
|
|
||||||
|
|
||||||
export enum StatutAvenantType {
|
|
||||||
PROPOSE = 'propose',
|
|
||||||
ACCEPTE = 'accepte',
|
|
||||||
REFUSE = 'refuse',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('avenants_contrats')
|
|
||||||
export class AvenantContrat {
|
|
||||||
// Define your columns and relationships here
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Contrat, { onDelete: 'CASCADE' })
|
|
||||||
@JoinColumn({ name: 'id_contrat' })
|
|
||||||
contrat: Contrat;
|
|
||||||
|
|
||||||
@Column({ type: 'jsonb', nullable: true, name: 'modifications' })
|
|
||||||
modifications?: any;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'initie_par', referencedColumnName: 'id' })
|
|
||||||
initiator?: Users;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutAvenantType,
|
|
||||||
enumName: 'statut_avenant_type',
|
|
||||||
default: StatutAvenantType.PROPOSE,
|
|
||||||
name: 'statut'
|
|
||||||
})
|
|
||||||
statut: StatutAvenantType;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
createdAt: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryGeneratedColumn, Column,
|
|
||||||
OneToMany, ManyToMany, CreateDateColumn, JoinTable
|
|
||||||
} from 'typeorm';
|
|
||||||
import { Parents } from './parents.entity';
|
|
||||||
import { ParentsChildren } from './parents_children.entity';
|
|
||||||
import { Dossier } from './dossiers.entity';
|
|
||||||
|
|
||||||
export enum StatutEnfantType {
|
|
||||||
A_NAITRE = 'a_naitre',
|
|
||||||
ACTIF = 'actif',
|
|
||||||
SCOLARISE = 'scolarise',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GenreType {
|
|
||||||
H = 'H',
|
|
||||||
F = 'F',
|
|
||||||
AUTRE = 'Autre',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('enfants')
|
|
||||||
export class Children {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutEnfantType,
|
|
||||||
enumName: 'statut_enfant_type',
|
|
||||||
name: 'statut'
|
|
||||||
})
|
|
||||||
status: StatutEnfantType;
|
|
||||||
|
|
||||||
@Column({ name: 'prenom', length: 100, nullable: true })
|
|
||||||
first_name?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'nom', length: 100, nullable: true })
|
|
||||||
last_name?: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: GenreType,
|
|
||||||
enumName: 'genre_type',
|
|
||||||
nullable: true,
|
|
||||||
name: 'genre'
|
|
||||||
})
|
|
||||||
gender?: GenreType;
|
|
||||||
|
|
||||||
@Column({ type: 'date', nullable: true, name: 'date_naissance' })
|
|
||||||
birth_date?: Date;
|
|
||||||
|
|
||||||
@Column({ type: 'date', nullable: true, name: 'date_prevue_naissance' })
|
|
||||||
due_date?: Date;
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'photo_url', type: 'text' })
|
|
||||||
photo_url?: string;
|
|
||||||
|
|
||||||
@Column({ default: false, name: 'consentement_photo', type: 'boolean' })
|
|
||||||
consent_photo: boolean;
|
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'date_consentement_photo' })
|
|
||||||
consent_photo_at?: Date;
|
|
||||||
|
|
||||||
@Column({ default: false, name: 'est_multiple', type: 'boolean' })
|
|
||||||
is_multiple: boolean;
|
|
||||||
|
|
||||||
// Lien via table de jointure enfants_parents
|
|
||||||
@OneToMany(() => ParentsChildren, pc => pc.child)
|
|
||||||
parentLinks: ParentsChildren[];
|
|
||||||
|
|
||||||
// Relation avec Dossier
|
|
||||||
@OneToMany(() => Dossier, d => d.child)
|
|
||||||
dossiers: Dossier[];
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
|
||||||
import { Dossier } from "./dossiers.entity";
|
|
||||||
|
|
||||||
export enum StatutContratType {
|
|
||||||
BROUILLON = 'brouillon',
|
|
||||||
EN_ATTENTE_SIGNATURE = 'en_attente_signature',
|
|
||||||
VALIDE = 'valide',
|
|
||||||
RESILIE = 'resilie',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('contrats')
|
|
||||||
export class Contrat {
|
|
||||||
// Define your columns and relationships here
|
|
||||||
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@OneToOne(() => Dossier, {onDelete: 'CASCADE'} )
|
|
||||||
@JoinColumn({ name: 'id_dossier'})
|
|
||||||
dossier: Dossier;
|
|
||||||
|
|
||||||
@Column({type: 'jsonb', nullable: true, name: 'planning'})
|
|
||||||
planning?: any;
|
|
||||||
|
|
||||||
@Column({type: 'numeric', precision: 6, scale: 2, nullable: true, name: 'tarif_horaire'})
|
|
||||||
hourly_rate?: string;
|
|
||||||
|
|
||||||
@Column({type: 'numeric', precision: 6, scale: 2, nullable: true, name: 'indemnites_repas'})
|
|
||||||
meal_indemnity?: string;
|
|
||||||
|
|
||||||
@Column( { name: 'date_debut', type: 'date', nullable: true })
|
|
||||||
start_date?: Date;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutContratType,
|
|
||||||
enumName: 'statut_contrat_type',
|
|
||||||
default: StatutContratType.BROUILLON,
|
|
||||||
name: 'statut'
|
|
||||||
})
|
|
||||||
statut: StatutContratType;
|
|
||||||
|
|
||||||
@Column({type: 'boolean', default: false, name: 'signe_parent'})
|
|
||||||
signed_by_parent: boolean;
|
|
||||||
|
|
||||||
@Column({type: 'boolean', default: false, name: 'signe_am'})
|
|
||||||
signed_by_am: boolean;
|
|
||||||
|
|
||||||
@Column({type: 'timestamptz', nullable: true, name: 'finalise_le'})
|
|
||||||
finalized_at?: Date;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
updated_at: Date;
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryGeneratedColumn, Column,
|
|
||||||
ManyToOne, OneToMany, CreateDateColumn, UpdateDateColumn, JoinColumn
|
|
||||||
} from 'typeorm';
|
|
||||||
import { Parents } from './parents.entity';
|
|
||||||
import { Children } from './children.entity';
|
|
||||||
import { Message } from './messages.entity';
|
|
||||||
|
|
||||||
export enum StatutDossierType {
|
|
||||||
ENVOYE = 'envoye',
|
|
||||||
ACCEPTE = 'accepte',
|
|
||||||
REFUSE = 'refuse',
|
|
||||||
CLOTURE = 'cloture',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('dossiers')
|
|
||||||
export class Dossier {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Parents, p => p.dossiers, { onDelete: 'CASCADE', nullable: false })
|
|
||||||
@JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
|
|
||||||
parent: Parents;
|
|
||||||
|
|
||||||
@ManyToOne(() => Children, c => c.dossiers, { onDelete: 'CASCADE', nullable: false })
|
|
||||||
@JoinColumn({ name: 'id_enfant', referencedColumnName: 'id' })
|
|
||||||
child: Children;
|
|
||||||
|
|
||||||
@Column({ type: 'text', nullable: true, name: 'presentation' })
|
|
||||||
presentation?: string;
|
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 50, nullable: true, name: 'type_contrat' })
|
|
||||||
type_contrat?: string;
|
|
||||||
|
|
||||||
@Column({ type: 'boolean', default: false, name: 'repas' })
|
|
||||||
meals: boolean;
|
|
||||||
|
|
||||||
@Column({ type: 'numeric', precision: 10, scale: 2, nullable: true, name: 'budget' })
|
|
||||||
budget?: number;
|
|
||||||
|
|
||||||
@Column({ type: 'jsonb', nullable: true, name: 'planning_souhaite' })
|
|
||||||
desired_schedule?: any;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutDossierType,
|
|
||||||
enumName: 'statut_dossier_type',
|
|
||||||
default: StatutDossierType.ENVOYE,
|
|
||||||
name: 'statut'
|
|
||||||
})
|
|
||||||
status: StatutDossierType;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
updated_at: Date;
|
|
||||||
|
|
||||||
@OneToMany(() => Message, m => m.dossier)
|
|
||||||
messages: Message[];
|
|
||||||
}
|
|
||||||
@ -1,79 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
|
||||||
import { Children } from "./children.entity";
|
|
||||||
import { Users } from "./users.entity";
|
|
||||||
import { Parents } from "./parents.entity";
|
|
||||||
|
|
||||||
export enum TypeEvenementType {
|
|
||||||
ABSENCE_ENFANT = 'absence_enfant',
|
|
||||||
CONGE_AM = 'conge_am',
|
|
||||||
CONGE_PARENT = 'conge_parent',
|
|
||||||
ARRET_MALADIE_AM = 'arret_maladie_am',
|
|
||||||
EVENEMENT_RPE = 'evenement_rpe',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum StatutEvenementType {
|
|
||||||
PROPOSE = 'propose',
|
|
||||||
VALIDE = 'valide',
|
|
||||||
REFUSE = 'refuse',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('evenements')
|
|
||||||
export class Evenement {
|
|
||||||
// Define your columns and relationships here
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: TypeEvenementType,
|
|
||||||
enumName: 'type_evenement_type',
|
|
||||||
name: 'type'
|
|
||||||
})
|
|
||||||
type: TypeEvenementType;
|
|
||||||
|
|
||||||
@ManyToOne(() => Children, { onDelete: 'CASCADE', nullable: true })
|
|
||||||
@JoinColumn({ name: 'id_enfant', referencedColumnName: 'id' })
|
|
||||||
child?: Children;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'id_am', referencedColumnName: 'id' })
|
|
||||||
assistanteMaternelle?: Users;
|
|
||||||
|
|
||||||
@ManyToOne(() => Parents, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
|
|
||||||
parent?: Parents;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'cree_par', referencedColumnName: 'id' })
|
|
||||||
created_by?: Users;
|
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'date_debut' })
|
|
||||||
start_date?: Date;
|
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'date_fin' })
|
|
||||||
end_date?: Date;
|
|
||||||
|
|
||||||
@Column({ type: 'text', nullable: true, name: 'commentaires' })
|
|
||||||
comments?: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutEvenementType,
|
|
||||||
enumName: 'statut_evenement_type',
|
|
||||||
name: 'statut',
|
|
||||||
default: StatutEvenementType.PROPOSE
|
|
||||||
})
|
|
||||||
status: StatutEvenementType;
|
|
||||||
|
|
||||||
@Column({type: 'timestamptz', nullable: true, name: 'delai_grace'})
|
|
||||||
grace_deadline?: Date;
|
|
||||||
|
|
||||||
@Column({type: 'boolean', default: false, name: 'urgent'})
|
|
||||||
urgent: boolean;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
updated_at: Date;
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryGeneratedColumn, Column,
|
|
||||||
ManyToOne, JoinColumn, CreateDateColumn
|
|
||||||
} from 'typeorm';
|
|
||||||
import { Dossier } from './dossiers.entity';
|
|
||||||
import { Users } from './users.entity';
|
|
||||||
|
|
||||||
@Entity('messages')
|
|
||||||
export class Message {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Dossier, d => d.messages, { onDelete: 'CASCADE', nullable: false })
|
|
||||||
@JoinColumn({ name: 'id_dossier' })
|
|
||||||
dossier: Dossier;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, u => u.messages, { onDelete: 'CASCADE', nullable: false })
|
|
||||||
@JoinColumn({ name: 'id_expediteur' })
|
|
||||||
sender: Users;
|
|
||||||
|
|
||||||
@Column({ type: 'text', name: 'contenu' })
|
|
||||||
content: string;
|
|
||||||
|
|
||||||
@Column({ type: 'boolean', name: 're_redige_par_ia', default: false })
|
|
||||||
reRedigeParIA: boolean;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
|
||||||
import { Users } from "./users.entity";
|
|
||||||
|
|
||||||
@Entity('notifications')
|
|
||||||
export class Notification {
|
|
||||||
// Define your columns and relationships here
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, { onDelete: 'CASCADE' })
|
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
|
||||||
user: Users;
|
|
||||||
|
|
||||||
@Column({ type: 'text', name: 'contenu' })
|
|
||||||
content: string;
|
|
||||||
|
|
||||||
@Column({type: 'boolean', name: 'lu', default: false})
|
|
||||||
read: boolean;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryColumn, OneToOne, JoinColumn,
|
|
||||||
ManyToOne, OneToMany
|
|
||||||
} from 'typeorm';
|
|
||||||
import { Users } from './users.entity';
|
|
||||||
import { ParentsChildren } from './parents_children.entity';
|
|
||||||
import { Dossier } from './dossiers.entity';
|
|
||||||
|
|
||||||
@Entity('parents', { schema: 'public' })
|
|
||||||
export class Parents {
|
|
||||||
// PK = FK vers utilisateurs.id
|
|
||||||
@PrimaryColumn('uuid', { name: 'id_utilisateur' })
|
|
||||||
user_id: string;
|
|
||||||
|
|
||||||
@OneToOne(() => Users, user => user.parent, { onDelete: 'CASCADE' })
|
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
|
||||||
user: Users;
|
|
||||||
|
|
||||||
// Co-parent (nullable) → FK vers utilisateurs.id
|
|
||||||
@ManyToOne(() => Users, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'id_co_parent', referencedColumnName: 'id' })
|
|
||||||
co_parent?: Users;
|
|
||||||
|
|
||||||
// Lien vers enfants via la table enfants_parents
|
|
||||||
@OneToMany(() => ParentsChildren, pc => pc.parent)
|
|
||||||
parentChildren: ParentsChildren[];
|
|
||||||
|
|
||||||
// Lien vers les dossiers de ce parent
|
|
||||||
@OneToMany(() => Dossier, d => d.parent)
|
|
||||||
dossiers: Dossier[];
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, ManyToOne, JoinColumn, PrimaryColumn
|
|
||||||
} from 'typeorm';
|
|
||||||
import { Parents } from './parents.entity';
|
|
||||||
import { Children } from './children.entity';
|
|
||||||
|
|
||||||
@Entity('enfants_parents', { schema: 'public' })
|
|
||||||
export class ParentsChildren {
|
|
||||||
@PrimaryColumn('uuid', { name: 'id_parent' })
|
|
||||||
parentId: string;
|
|
||||||
|
|
||||||
@PrimaryColumn('uuid', { name: 'id_enfant' })
|
|
||||||
enfantId: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Parents, p => p.parentChildren, { onDelete: 'CASCADE' })
|
|
||||||
@JoinColumn({ name: 'id_parent', referencedColumnName: 'user_id' })
|
|
||||||
parent: Parents;
|
|
||||||
|
|
||||||
@ManyToOne(() => Children, c => c.parentLinks, { onDelete: 'CASCADE' })
|
|
||||||
@JoinColumn({ name: 'id_enfant', referencedColumnName: 'id' })
|
|
||||||
child: Children;
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
|
||||||
import { Users } from "./users.entity";
|
|
||||||
|
|
||||||
@Entity('signalements_bugs')
|
|
||||||
export class SignalementBug {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, {nullable: true})
|
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
|
||||||
user?: Users;
|
|
||||||
|
|
||||||
@Column({ type: 'text', name: 'description'})
|
|
||||||
description: string;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
|
||||||
import { Users } from "./users.entity";
|
|
||||||
|
|
||||||
@Entity('uploads')
|
|
||||||
export class Upload {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, { onDelete: 'SET NULL', nullable: true })
|
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
|
||||||
user?: Users;
|
|
||||||
|
|
||||||
@Column({ type: 'text', name: 'fichier_url' })
|
|
||||||
file_url: string;
|
|
||||||
|
|
||||||
@Column({type: 'varchar', length: 50, nullable: true, name: 'type'})
|
|
||||||
type?: string;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
created_at: Date;
|
|
||||||
}
|
|
||||||
@ -1,150 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryGeneratedColumn, Column,
|
|
||||||
CreateDateColumn, UpdateDateColumn,
|
|
||||||
OneToOne, OneToMany
|
|
||||||
} from 'typeorm';
|
|
||||||
import { AssistanteMaternelle } from './assistantes_maternelles.entity';
|
|
||||||
import { Parents } from './parents.entity';
|
|
||||||
import { Message } from './messages.entity';
|
|
||||||
|
|
||||||
// Enums alignés avec la BDD PostgreSQL
|
|
||||||
export enum RoleType {
|
|
||||||
PARENT = 'parent',
|
|
||||||
GESTIONNAIRE = 'gestionnaire',
|
|
||||||
SUPER_ADMIN = 'super_admin',
|
|
||||||
ASSISTANTE_MATERNELLE = 'assistante_maternelle',
|
|
||||||
ADMINISTRATEUR = 'administrateur',
|
|
||||||
}
|
|
||||||
|
|
||||||
//Enum pour definir le genre
|
|
||||||
export enum GenreType {
|
|
||||||
H = 'H',
|
|
||||||
F = 'F',
|
|
||||||
AUTRE = 'Autre',
|
|
||||||
}
|
|
||||||
|
|
||||||
//Enum pour definir le statut utilisateur
|
|
||||||
export enum StatutUtilisateurType {
|
|
||||||
EN_ATTENTE = 'en_attente',
|
|
||||||
ACTIF = 'actif',
|
|
||||||
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
|
|
||||||
@Entity('utilisateurs', { schema: 'public' })
|
|
||||||
export class Users {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column({ unique: true, name: 'email' })
|
|
||||||
email: string;
|
|
||||||
|
|
||||||
@Column({ name: 'password' })
|
|
||||||
password: string;
|
|
||||||
|
|
||||||
@Column({ name: 'prenom', nullable: true })
|
|
||||||
prenom?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'nom', nullable: true })
|
|
||||||
nom?: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: GenreType,
|
|
||||||
enumName: 'genre_type', // correspond à l'enum de la db psql
|
|
||||||
nullable: true,
|
|
||||||
name: 'genre'
|
|
||||||
})
|
|
||||||
genre?: GenreType;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: RoleType,
|
|
||||||
enumName: 'role_type', // correspond à l'enum de la db psql
|
|
||||||
name: 'role'
|
|
||||||
})
|
|
||||||
role: RoleType;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutUtilisateurType,
|
|
||||||
enumName: 'statut_utilisateur_type', // correspond à l'enum de la db psql
|
|
||||||
default: StatutUtilisateurType.EN_ATTENTE,
|
|
||||||
name: 'statut'
|
|
||||||
})
|
|
||||||
statut: StatutUtilisateurType;
|
|
||||||
|
|
||||||
@Column({ type: 'enum',
|
|
||||||
enum: SituationFamilialeType,
|
|
||||||
enumName: 'situation_familiale_type',
|
|
||||||
nullable: true,
|
|
||||||
name: 'situation_familiale'
|
|
||||||
})
|
|
||||||
situation_familiale?: SituationFamilialeType;
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'telephone' })
|
|
||||||
telephone?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'mobile', nullable: true })
|
|
||||||
mobile?: string;
|
|
||||||
|
|
||||||
@Column({ name: 'telephone_fixe', nullable: true })
|
|
||||||
telephone_fixe?: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'adresse' })
|
|
||||||
adresse?: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'photo_url' })
|
|
||||||
photo_url?: string;
|
|
||||||
|
|
||||||
@Column({ default: false, name: 'consentement_photo' })
|
|
||||||
consentement_photo: boolean;
|
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'date_consentement_photo' })
|
|
||||||
date_consentement_photo?: Date;
|
|
||||||
|
|
||||||
@Column({ default: false, name: 'changement_mdp_obligatoire' })
|
|
||||||
changement_mdp_obligatoire: boolean;
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'ville' })
|
|
||||||
ville?: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'code_postal' })
|
|
||||||
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' })
|
|
||||||
cree_le: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
modifie_le: Date;
|
|
||||||
|
|
||||||
// Relations
|
|
||||||
@OneToOne(() => AssistanteMaternelle, a => a.user)
|
|
||||||
assistanteMaternelle?: AssistanteMaternelle;
|
|
||||||
|
|
||||||
@OneToOne(() => Parents, p => p.user)
|
|
||||||
parent?: Parents;
|
|
||||||
|
|
||||||
@OneToMany(() => Message, m => m.sender)
|
|
||||||
messages?: Message[];
|
|
||||||
|
|
||||||
@OneToMany(() => Parents, parent => parent.co_parent)
|
|
||||||
co_parent_in?: Parents[];
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
|
|
||||||
import { Users } from "./users.entity";
|
|
||||||
|
|
||||||
export enum StatutValidationType {
|
|
||||||
EN_ATTENTE = 'en_attente',
|
|
||||||
VALIDE = 'valide',
|
|
||||||
REFUSE = 'refuse',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('validations')
|
|
||||||
export class Validation {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Users, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
|
||||||
user?: Users;
|
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 50, name: 'type', nullable: true })
|
|
||||||
type: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: StatutValidationType,
|
|
||||||
enumName: 'statut_validation_type',
|
|
||||||
name: 'statut',
|
|
||||||
default: StatutValidationType.EN_ATTENTE
|
|
||||||
})
|
|
||||||
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' })
|
|
||||||
created_at: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
updated_at: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
59
src/main.ts
59
src/main.ts
@ -1,59 +1,8 @@
|
|||||||
import { NestFactory, Reflector } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
import { SwaggerModule } from '@nestjs/swagger/dist/swagger-module';
|
|
||||||
import { DocumentBuilder } from '@nestjs/swagger';
|
|
||||||
import { AuthGuard } from './common/guards/auth.guard';
|
|
||||||
import { JwtService } from '@nestjs/jwt';
|
|
||||||
import { RolesGuard } from './common/guards/roles.guard';
|
|
||||||
import { ValidationPipe } from '@nestjs/common';
|
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule,
|
const app = await NestFactory.create(AppModule);
|
||||||
{ logger: ['error', 'warn', 'log', 'debug', 'verbose'] });
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
app.enableCors();
|
|
||||||
|
|
||||||
app.useGlobalPipes(
|
|
||||||
new ValidationPipe({
|
|
||||||
whitelist: true,
|
|
||||||
forbidNonWhitelisted: true,
|
|
||||||
transform: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const configService = app.get(ConfigService);
|
|
||||||
|
|
||||||
const port = configService.get<number>('app.port', 3000);
|
|
||||||
app.setGlobalPrefix('api/v1');
|
|
||||||
|
|
||||||
const config = new DocumentBuilder()
|
|
||||||
.setTitle("P'titsPas API")
|
|
||||||
.setDescription("API pour l'application P'titsPas")
|
|
||||||
.setVersion('1.0.0')
|
|
||||||
.addBearerAuth(
|
|
||||||
{
|
|
||||||
type: 'http',
|
|
||||||
scheme: 'Bearer',
|
|
||||||
bearerFormat: 'JWT',
|
|
||||||
name: 'Authorization',
|
|
||||||
description: 'Enter JWT token',
|
|
||||||
in: 'header',
|
|
||||||
},
|
|
||||||
'access-token',
|
|
||||||
)
|
|
||||||
//.addServer('/api/v1')
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const document = SwaggerModule.createDocument(app, config);
|
|
||||||
SwaggerModule.setup('api/v1/swagger', app, document);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await app.listen(port);
|
|
||||||
console.log(`✅ P'titsPas API is running on: ${await app.getUrl()}`);
|
|
||||||
}
|
}
|
||||||
|
bootstrap();
|
||||||
bootstrap().catch((err) => {
|
|
||||||
console.error('❌ Error starting the application:', err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
|
||||||
|
|
||||||
describe('AssistantesMaternellesController', () => {
|
|
||||||
let controller: AssistantesMaternellesController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [AssistantesMaternellesController],
|
|
||||||
providers: [AssistantesMaternellesService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
controller = module.get<AssistantesMaternellesController>(AssistantesMaternellesController);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(controller).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,81 +0,0 @@
|
|||||||
import {
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Body,
|
|
||||||
Patch,
|
|
||||||
Param,
|
|
||||||
Delete,
|
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
|
||||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
|
||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
|
||||||
import { CreateAssistanteDto } from '../user/dto/create_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")
|
|
||||||
@ApiBearerAuth('access-token')
|
|
||||||
@UseGuards(AuthGuard, RolesGuard)
|
|
||||||
@Controller('assistantes-maternelles')
|
|
||||||
export class AssistantesMaternellesController {
|
|
||||||
constructor(private readonly assistantesMaternellesService: AssistantesMaternellesService) { }
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@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' })
|
|
||||||
@ApiBody({ type: CreateAssistanteDto })
|
|
||||||
@Post()
|
|
||||||
create(@Body() dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
|
||||||
return this.assistantesMaternellesService.create(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Get()
|
|
||||||
@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' })
|
|
||||||
getAll(): Promise<AssistanteMaternelle[]> {
|
|
||||||
return this.assistantesMaternellesService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Get(':id')
|
|
||||||
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
|
||||||
@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' })
|
|
||||||
getOne(@Param('id') user_id: string): Promise<AssistanteMaternelle> {
|
|
||||||
return this.assistantesMaternellesService.findOne(user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@ApiBody({ type: UpdateAssistanteDto })
|
|
||||||
@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: 404, description: 'Nounou non trouvée' })
|
|
||||||
@ApiParam({ name: 'id', description: "UUID de la nounou" })
|
|
||||||
@Patch(':id')
|
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
|
||||||
return this.assistantesMaternellesService.update(id, dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
|
||||||
@ApiOperation({ summary: 'Supprimer une nounou' })
|
|
||||||
@ApiResponse({ status: 200, description: 'Nounou supprimée avec succès' })
|
|
||||||
@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')
|
|
||||||
remove(@Param('id') id: string): Promise<{ message: string }>
|
|
||||||
{
|
|
||||||
return this.assistantesMaternellesService.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
|
||||||
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({
|
|
||||||
imports: [TypeOrmModule.forFeature([AssistanteMaternelle, Users]),
|
|
||||||
AuthModule
|
|
||||||
],
|
|
||||||
controllers: [AssistantesMaternellesController],
|
|
||||||
providers: [AssistantesMaternellesService],
|
|
||||||
exports: [
|
|
||||||
AssistantesMaternellesService,
|
|
||||||
TypeOrmModule,
|
|
||||||
],
|
|
||||||
})
|
|
||||||
export class AssistantesMaternellesModule { }
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
|
||||||
|
|
||||||
describe('AssistantesMaternellesService', () => {
|
|
||||||
let service: AssistantesMaternellesService;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [AssistantesMaternellesService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
service = module.get<AssistantesMaternellesService>(AssistantesMaternellesService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
import {
|
|
||||||
BadRequestException,
|
|
||||||
ConflictException,
|
|
||||||
Injectable,
|
|
||||||
NotFoundException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
|
||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
|
||||||
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
|
||||||
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AssistantesMaternellesService {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(AssistanteMaternelle)
|
|
||||||
private readonly assistantesMaternelleRepository: Repository<AssistanteMaternelle>,
|
|
||||||
@InjectRepository(Users)
|
|
||||||
private readonly usersRepository: Repository<Users>
|
|
||||||
) {}
|
|
||||||
|
|
||||||
// Création d’une assistante maternelle
|
|
||||||
async create(dto: CreateAssistanteDto): Promise<AssistanteMaternelle> {
|
|
||||||
const user = await this.usersRepository.findOneBy({ id: dto.user_id });
|
|
||||||
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
|
||||||
if (user.role !== RoleType.ASSISTANTE_MATERNELLE) {
|
|
||||||
throw new BadRequestException('Accès réservé aux assistantes maternelles');
|
|
||||||
}
|
|
||||||
|
|
||||||
const exist = await this.assistantesMaternelleRepository.findOneBy({ user_id: dto.user_id });
|
|
||||||
if (exist) throw new ConflictException('Assistante maternelle déjà existante');
|
|
||||||
|
|
||||||
const entity = this.assistantesMaternelleRepository.create({
|
|
||||||
user_id: dto.user_id,
|
|
||||||
user: { ...user, role: RoleType.ASSISTANTE_MATERNELLE },
|
|
||||||
approval_number: dto.approval_number,
|
|
||||||
nir: dto.nir,
|
|
||||||
max_children: dto.max_children,
|
|
||||||
biography: dto.biography,
|
|
||||||
available: dto.available ?? true,
|
|
||||||
residence_city: dto.residence_city,
|
|
||||||
agreement_date: dto.agreement_date ? new Date(dto.agreement_date) : undefined,
|
|
||||||
years_experience: dto.years_experience,
|
|
||||||
specialty: dto.specialty,
|
|
||||||
places_available: dto.places_available,
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.assistantesMaternelleRepository.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Liste des assistantes maternelles
|
|
||||||
async findAll(): Promise<AssistanteMaternelle[]> {
|
|
||||||
return this.assistantesMaternelleRepository.find({
|
|
||||||
relations: ['user'],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Récupérer une assistante maternelle par user_id
|
|
||||||
async findOne(user_id: string): Promise<AssistanteMaternelle> {
|
|
||||||
const assistante = await this.assistantesMaternelleRepository.findOne({
|
|
||||||
where: { user_id },
|
|
||||||
relations: ['user'],
|
|
||||||
});
|
|
||||||
if (!assistante) throw new NotFoundException('Assistante maternelle introuvable');
|
|
||||||
return assistante;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour
|
|
||||||
async update(id: string, dto: UpdateAssistanteDto): Promise<AssistanteMaternelle> {
|
|
||||||
await this.assistantesMaternelleRepository.update(id, dto);
|
|
||||||
return this.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Suppression d’une assistante maternelle
|
|
||||||
async remove(id: string): Promise<{ message: string }> {
|
|
||||||
await this.assistantesMaternelleRepository.delete(id);
|
|
||||||
return { message: 'Assistante maternelle supprimée' };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { AuthController } from './auth.controller';
|
|
||||||
|
|
||||||
describe('AuthController', () => {
|
|
||||||
let controller: AuthController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [AuthController],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
controller = module.get<AuthController>(AuthController);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(controller).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,75 +0,0 @@
|
|||||||
import { Body, Controller, Get, Post, Req, UnauthorizedException, UseGuards } from '@nestjs/common';
|
|
||||||
import { LoginDto } from './dto/login.dto';
|
|
||||||
import { AuthService } from './auth.service';
|
|
||||||
import { Public } from 'src/common/decorators/public.decorator';
|
|
||||||
import { RegisterDto } from './dto/register.dto';
|
|
||||||
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
||||||
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')
|
|
||||||
@Controller('auth')
|
|
||||||
export class AuthController {
|
|
||||||
constructor(
|
|
||||||
private readonly authService: AuthService,
|
|
||||||
private readonly userService: UserService,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
|
|
||||||
@Public()
|
|
||||||
@ApiOperation({ summary: 'Connexion' })
|
|
||||||
@Post('login')
|
|
||||||
async login(@Body() dto: LoginDto) {
|
|
||||||
return this.authService.login(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Public()
|
|
||||||
@Post('register')
|
|
||||||
@ApiOperation({ summary: 'Inscription' })
|
|
||||||
async register(@Body() dto: RegisterDto) {
|
|
||||||
return this.authService.register(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Public()
|
|
||||||
@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' })
|
|
||||||
async refresh(@Body() dto: RefreshTokenDto) {
|
|
||||||
return this.authService.refreshTokens(dto.refresh_token);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('me')
|
|
||||||
@UseGuards(AuthGuard)
|
|
||||||
@ApiBearerAuth('access-token')
|
|
||||||
@ApiOperation({ summary: "Récupérer le profil complet de l'utilisateur connecté" })
|
|
||||||
@ApiResponse({ status: 200, type: ProfileResponseDto })
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
import { forwardRef, Module } from '@nestjs/common';
|
|
||||||
import { AuthController } from './auth.controller';
|
|
||||||
import { AuthService } from './auth.service';
|
|
||||||
import { UserModule } from '../user/user.module';
|
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [
|
|
||||||
forwardRef(() => UserModule),
|
|
||||||
JwtModule.registerAsync({
|
|
||||||
imports: [ConfigModule],
|
|
||||||
useFactory: (config: ConfigService) => ({
|
|
||||||
secret: config.get('jwt.secret'),
|
|
||||||
signOptions: { expiresIn: config.get('jwt.expirationTime') },
|
|
||||||
}),
|
|
||||||
inject: [ConfigService],
|
|
||||||
})
|
|
||||||
],
|
|
||||||
controllers: [AuthController],
|
|
||||||
providers: [AuthService],
|
|
||||||
exports: [AuthService, JwtModule],
|
|
||||||
})
|
|
||||||
export class AuthModule {}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { AuthService } from './auth.service';
|
|
||||||
|
|
||||||
describe('AuthService', () => {
|
|
||||||
let service: AuthService;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [AuthService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
service = module.get<AuthService>(AuthService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,137 +0,0 @@
|
|||||||
import {
|
|
||||||
ConflictException,
|
|
||||||
Injectable,
|
|
||||||
UnauthorizedException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { UserService } from '../user/user.service';
|
|
||||||
import { JwtService } from '@nestjs/jwt';
|
|
||||||
import * as bcrypt from 'bcrypt';
|
|
||||||
import { RegisterDto } from './dto/register.dto';
|
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
import { RoleType, StatutUtilisateurType, Users } from 'src/entities/users.entity';
|
|
||||||
import { LoginDto } from './dto/login.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AuthService {
|
|
||||||
constructor(
|
|
||||||
private readonly usersService: UserService,
|
|
||||||
private readonly jwtService: JwtService,
|
|
||||||
private readonly configService: ConfigService,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Génère un access_token et un refresh_token
|
|
||||||
*/
|
|
||||||
async generateTokens(userId: string, email: string, role: RoleType) {
|
|
||||||
const accessSecret = this.configService.get<string>('jwt.accessSecret');
|
|
||||||
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([
|
|
||||||
this.jwtService.signAsync({ sub: userId, email, role }, { secret: accessSecret, expiresIn: accessExpiresIn }),
|
|
||||||
this.jwtService.signAsync({ sub: userId }, { secret: refreshSecret, expiresIn: refreshExpiresIn }),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
access_token: accessToken,
|
|
||||||
refresh_token: refreshToken,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connexion utilisateur
|
|
||||||
*/
|
|
||||||
async login(dto: LoginDto) {
|
|
||||||
try {
|
|
||||||
const user = await this.usersService.findByEmailOrNull(dto.email);
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
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);
|
|
||||||
console.log("Résultat bcrypt.compare:", isMatch);
|
|
||||||
if (!isMatch) {
|
|
||||||
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);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Erreur de connexion :', error);
|
|
||||||
throw new UnauthorizedException('Identifiants invalides');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rafraîchir les tokens
|
|
||||||
*/
|
|
||||||
async refreshTokens(refreshToken: string) {
|
|
||||||
try {
|
|
||||||
const payload = await this.jwtService.verifyAsync(refreshToken, {
|
|
||||||
secret: this.configService.get<string>('jwt.refreshSecret'),
|
|
||||||
});
|
|
||||||
|
|
||||||
const user = await this.usersService.findOne(payload.sub);
|
|
||||||
if (!user) {
|
|
||||||
throw new UnauthorizedException('Utilisateur introuvable');
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.generateTokens(user.id, user.email, user.role);
|
|
||||||
} catch {
|
|
||||||
throw new UnauthorizedException('Refresh token invalide');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inscription utilisateur lambda (parent ou assistante maternelle)
|
|
||||||
*/
|
|
||||||
async register(registerDto: RegisterDto) {
|
|
||||||
const exists = await this.usersService.findByEmailOrNull(registerDto.email);
|
|
||||||
if (exists) {
|
|
||||||
throw new ConflictException('Email déjà utilisé');
|
|
||||||
}
|
|
||||||
|
|
||||||
const allowedRoles = new Set<RoleType>([RoleType.PARENT, RoleType.ASSISTANTE_MATERNELLE]);
|
|
||||||
if (!allowedRoles.has(registerDto.role)) {
|
|
||||||
registerDto.role = RoleType.PARENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
registerDto.statut = StatutUtilisateurType.EN_ATTENTE;
|
|
||||||
|
|
||||||
if (!registerDto.consentement_photo) {
|
|
||||||
registerDto.date_consentement_photo = null;
|
|
||||||
} else if (registerDto.date_consentement_photo) {
|
|
||||||
const date = new Date(registerDto.date_consentement_photo);
|
|
||||||
if (isNaN(date.getTime())) {
|
|
||||||
registerDto.date_consentement_photo = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = await this.usersService.createUser(registerDto);
|
|
||||||
const tokens = await this.generateTokens(user.id, user.email, user.role);
|
|
||||||
|
|
||||||
return {
|
|
||||||
...tokens,
|
|
||||||
user: {
|
|
||||||
id: user.id,
|
|
||||||
email: user.email,
|
|
||||||
role: user.role,
|
|
||||||
prenom: user.prenom,
|
|
||||||
nom: user.nom,
|
|
||||||
statut: user.statut,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async logout(userId: string) {
|
|
||||||
// Pour le moment envoyer un message clair
|
|
||||||
return { success: true, message: 'Deconnexion'}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger";
|
|
||||||
import { IsEmail, IsString, MaxLength, MinLength } from "class-validator";
|
|
||||||
|
|
||||||
export class LoginDto {
|
|
||||||
@ApiProperty({ example: 'mon.utilisateur@exemple.com', description: "Adresse email de l'utililisateur" })
|
|
||||||
@IsEmail()
|
|
||||||
email: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: "Mon_motdepasse_fort_1234?",
|
|
||||||
description: "Mot de passe de l'utilisateur"
|
|
||||||
})
|
|
||||||
@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' })
|
|
||||||
@MaxLength(50)
|
|
||||||
password: string;
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
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 +0,0 @@
|
|||||||
import { ApiProperty, OmitType } from '@nestjs/swagger';
|
|
||||||
import { IsEnum, IsOptional } from 'class-validator';
|
|
||||||
import { CreateUserDto } from '../../user/dto/create_user.dto';
|
|
||||||
import { RoleType, StatutUtilisateurType } from 'src/entities/users.entity';
|
|
||||||
|
|
||||||
export class RegisterDto extends OmitType(CreateUserDto, ['changement_mdp_obligatoire'] as const) {
|
|
||||||
@ApiProperty({ enum: [RoleType.ASSISTANTE_MATERNELLE, RoleType.PARENT], default: RoleType.PARENT })
|
|
||||||
@IsEnum(RoleType)
|
|
||||||
role: RoleType = RoleType.PARENT;
|
|
||||||
|
|
||||||
@IsEnum(StatutUtilisateurType)
|
|
||||||
@IsOptional()
|
|
||||||
statut?: StatutUtilisateurType = StatutUtilisateurType.EN_ATTENTE;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Module({})
|
|
||||||
export class DossiersModule {}
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from '@nestjs/swagger';
|
|
||||||
import { CreateEnfantsDto } from './create_enfants.dto';
|
|
||||||
|
|
||||||
export class UpdateEnfantsDto extends PartialType(CreateEnfantsDto) {}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
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 { }
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,113 +0,0 @@
|
|||||||
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,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { ParentsController } from './parents.controller';
|
|
||||||
|
|
||||||
describe('ParentsController', () => {
|
|
||||||
let controller: ParentsController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [ParentsController],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
controller = module.get<ParentsController>(ParentsController);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(controller).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
import {
|
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Delete,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Patch,
|
|
||||||
Post,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ParentsService } from './parents.service';
|
|
||||||
import { Parents } from 'src/entities/parents.entity';
|
|
||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
|
||||||
import { RoleType } from 'src/entities/users.entity';
|
|
||||||
import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
||||||
import { CreateParentDto } from '../user/dto/create_parent.dto';
|
|
||||||
import { UpdateParentsDto } from '../user/dto/update_parent.dto';
|
|
||||||
|
|
||||||
@ApiTags('Parents')
|
|
||||||
@Controller('parents')
|
|
||||||
export class ParentsController {
|
|
||||||
constructor(private readonly parentsService: ParentsService) {}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Get()
|
|
||||||
@ApiResponse({ status: 200, type: [Parents], description: 'Liste des parents' })
|
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
||||||
getAll(): Promise<Parents[]> {
|
|
||||||
return this.parentsService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Get(':id')
|
|
||||||
@ApiResponse({ status: 200, type: Parents, description: 'Détails du parent par ID utilisateur' })
|
|
||||||
@ApiResponse({ status: 404, description: 'Parent non trouvé' })
|
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
||||||
getOne(@Param('id') user_id: string): Promise<Parents> {
|
|
||||||
return this.parentsService.findOne(user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Post()
|
|
||||||
@ApiBody({ type: CreateParentDto })
|
|
||||||
@ApiResponse({ status: 201, type: Parents, description: 'Parent créé avec succès' })
|
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
||||||
create(@Body() dto: CreateParentDto): Promise<Parents> {
|
|
||||||
return this.parentsService.create(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@Patch(':id')
|
|
||||||
@ApiBody({ type: UpdateParentsDto })
|
|
||||||
@ApiResponse({ status: 200, type: Parents, description: 'Parent mis à jour avec succès' })
|
|
||||||
@ApiResponse({ status: 404, description: 'Parent introuvable' })
|
|
||||||
@ApiResponse({ status: 403, description: 'Accès refusé !' })
|
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateParentsDto): Promise<Parents> {
|
|
||||||
return this.parentsService.update(id, dto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { Parents } from 'src/entities/parents.entity';
|
|
||||||
import { ParentsController } from './parents.controller';
|
|
||||||
import { ParentsService } from './parents.service';
|
|
||||||
import { Users } from 'src/entities/users.entity';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [TypeOrmModule.forFeature([Parents, Users])],
|
|
||||||
controllers: [ParentsController],
|
|
||||||
providers: [ParentsService],
|
|
||||||
exports: [ParentsService,
|
|
||||||
TypeOrmModule,
|
|
||||||
],
|
|
||||||
})
|
|
||||||
export class ParentsModule { }
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { ParentsService } from './parents.service';
|
|
||||||
|
|
||||||
describe('ParentsService', () => {
|
|
||||||
let service: ParentsService;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [ParentsService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
service = module.get<ParentsService>(ParentsService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
import {
|
|
||||||
BadRequestException,
|
|
||||||
ConflictException,
|
|
||||||
Injectable,
|
|
||||||
NotFoundException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { Parents } from 'src/entities/parents.entity';
|
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
|
||||||
import { CreateParentDto } from '../user/dto/create_parent.dto';
|
|
||||||
import { UpdateParentsDto } from '../user/dto/update_parent.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ParentsService {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Parents)
|
|
||||||
private readonly parentsRepository: Repository<Parents>,
|
|
||||||
@InjectRepository(Users)
|
|
||||||
private readonly usersRepository: Repository<Users>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
// Création d’un parent
|
|
||||||
async create(dto: CreateParentDto): Promise<Parents> {
|
|
||||||
const user = await this.usersRepository.findOneBy({ id: dto.user_id });
|
|
||||||
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
|
||||||
if (user.role !== RoleType.PARENT) {
|
|
||||||
throw new BadRequestException('Accès réservé aux parents');
|
|
||||||
}
|
|
||||||
|
|
||||||
const exist = await this.parentsRepository.findOneBy({ user_id: dto.user_id });
|
|
||||||
if (exist) throw new ConflictException('Ce parent existe déjà');
|
|
||||||
|
|
||||||
let co_parent: Users | null = null;
|
|
||||||
if (dto.co_parent_id) {
|
|
||||||
co_parent = await this.usersRepository.findOneBy({ id: dto.co_parent_id });
|
|
||||||
if (!co_parent) throw new NotFoundException('Co-parent introuvable');
|
|
||||||
if (co_parent.role !== RoleType.PARENT) {
|
|
||||||
throw new BadRequestException('Accès réservé aux parents');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const entity = this.parentsRepository.create({
|
|
||||||
user_id: dto.user_id,
|
|
||||||
user,
|
|
||||||
co_parent: co_parent ?? undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.parentsRepository.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Liste des parents
|
|
||||||
async findAll(): Promise<Parents[]> {
|
|
||||||
return this.parentsRepository.find({
|
|
||||||
relations: ['user', 'co_parent', 'parentChildren', 'dossiers'],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Récupérer un parent par user_id
|
|
||||||
async findOne(user_id: string): Promise<Parents> {
|
|
||||||
const parent = await this.parentsRepository.findOne({
|
|
||||||
where: { user_id },
|
|
||||||
relations: ['user', 'co_parent', 'parentChildren', 'dossiers'],
|
|
||||||
});
|
|
||||||
if (!parent) throw new NotFoundException('Parent introuvable');
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour
|
|
||||||
async update(id: string, dto: UpdateParentsDto): Promise<Parents> {
|
|
||||||
await this.parentsRepository.update(id, dto);
|
|
||||||
return this.findOne(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { OmitType } from "@nestjs/swagger";
|
|
||||||
import { CreateUserDto } from "./create_user.dto";
|
|
||||||
|
|
||||||
export class CreateAdminDto extends OmitType(CreateUserDto, ['role'] as const) {}
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
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";
|
|
||||||
|
|
||||||
export class CreateAssistanteDto extends OmitType(CreateUserDto, ['role', 'photo_url', 'consentement_photo'] as const) {
|
|
||||||
@IsUUID()
|
|
||||||
@IsNotEmpty()
|
|
||||||
user_id?: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@Length(1, 50)
|
|
||||||
approval_number: string;
|
|
||||||
|
|
||||||
@Matches(/^\d{15}$/)
|
|
||||||
@IsNotEmpty()
|
|
||||||
nir: string;
|
|
||||||
|
|
||||||
@IsInt()
|
|
||||||
@Min(1)
|
|
||||||
@Max(10)
|
|
||||||
@IsNotEmpty()
|
|
||||||
max_children: number;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
photo_url: string;
|
|
||||||
|
|
||||||
@IsBoolean()
|
|
||||||
@IsNotEmpty()
|
|
||||||
consentement_photo: boolean;
|
|
||||||
|
|
||||||
@IsDateString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
agreement_date: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@Length(1, 100)
|
|
||||||
residence_city: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
biography?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
available?: boolean;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
years_experience?: number;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
specialty?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
places_available?: number;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { OmitType } from "@nestjs/swagger";
|
|
||||||
import { CreateUserDto } from "./create_user.dto";
|
|
||||||
|
|
||||||
export class CreateGestionnaireDto extends OmitType(CreateUserDto, ['role'] as const) {}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
import { OmitType } from "@nestjs/swagger";
|
|
||||||
import { CreateUserDto } from "./create_user.dto";
|
|
||||||
import { IsNotEmpty, IsOptional, IsString, IsUUID } from "class-validator";
|
|
||||||
|
|
||||||
export class CreateParentDto extends OmitType(CreateUserDto, ['role', 'photo_url'] as const) {
|
|
||||||
@IsUUID()
|
|
||||||
@IsNotEmpty()
|
|
||||||
user_id: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsUUID()
|
|
||||||
co_parent_id?: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
photo_url: string;
|
|
||||||
}
|
|
||||||
@ -1,105 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import {
|
|
||||||
IsBoolean,
|
|
||||||
IsDateString,
|
|
||||||
IsEmail,
|
|
||||||
IsEnum,
|
|
||||||
IsNotEmpty,
|
|
||||||
IsOptional,
|
|
||||||
IsString,
|
|
||||||
MinLength,
|
|
||||||
MaxLength,
|
|
||||||
} from 'class-validator';
|
|
||||||
import { RoleType, GenreType, StatutUtilisateurType, SituationFamilialeType } from 'src/entities/users.entity';
|
|
||||||
|
|
||||||
export class CreateUserDto {
|
|
||||||
@ApiProperty({ example: 'sosso.test@example.com' })
|
|
||||||
@IsEmail()
|
|
||||||
@IsNotEmpty()
|
|
||||||
email: string;
|
|
||||||
|
|
||||||
@ApiProperty({ minLength: 6, example: 'Mon_motdepasse_fort_1234?' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@MinLength(6)
|
|
||||||
password: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: 'Julien' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@MaxLength(100)
|
|
||||||
prenom: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: 'Dupont' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@MaxLength(100)
|
|
||||||
nom: string;
|
|
||||||
|
|
||||||
@ApiProperty({ enum: GenreType, required: false, default: GenreType.AUTRE })
|
|
||||||
@IsOptional()
|
|
||||||
@IsEnum(GenreType)
|
|
||||||
genre?: GenreType = GenreType.AUTRE;
|
|
||||||
|
|
||||||
@ApiProperty({ enum: RoleType })
|
|
||||||
@IsEnum(RoleType)
|
|
||||||
role: RoleType;
|
|
||||||
|
|
||||||
@ApiProperty({ enum: StatutUtilisateurType, required: false, default: StatutUtilisateurType.EN_ATTENTE })
|
|
||||||
@IsOptional()
|
|
||||||
@IsEnum(StatutUtilisateurType)
|
|
||||||
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' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@MaxLength(20)
|
|
||||||
telephone: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: 'Paris', required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@MaxLength(150)
|
|
||||||
ville?: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: '75000', required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@MaxLength(10)
|
|
||||||
code_postal?: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: '10 rue de la paix, 75000 Paris' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
adresse: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: 'https://example.com/photo.jpg', required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
photo_url?: string;
|
|
||||||
|
|
||||||
@ApiProperty({ default: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
consentement_photo?: boolean = false;
|
|
||||||
|
|
||||||
@ApiProperty({ required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString({}, { message: 'date_consentement_photo doit être une date ISO valide' })
|
|
||||||
date_consentement_photo?: string | null;
|
|
||||||
|
|
||||||
@ApiProperty({ default: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
changement_mdp_obligatoire?: boolean = false;
|
|
||||||
|
|
||||||
@ApiProperty({ example: true })
|
|
||||||
@IsBoolean()
|
|
||||||
@IsNotEmpty()
|
|
||||||
cguAccepted: boolean;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from "@nestjs/swagger";
|
|
||||||
import { CreateAdminDto } from "./create_admin.dto";
|
|
||||||
|
|
||||||
export class UpdateAdminDto extends PartialType(CreateAdminDto) {}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from "@nestjs/swagger";
|
|
||||||
import { CreateAssistanteDto } from "./create_assistante.dto";
|
|
||||||
|
|
||||||
export class UpdateAssistanteDto extends PartialType(CreateAssistanteDto) {}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from "@nestjs/swagger";
|
|
||||||
import { CreateGestionnaireDto } from "./create_gestionnaire.dto";
|
|
||||||
|
|
||||||
export class UpdateGestionnaireDto extends PartialType(CreateGestionnaireDto) {}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from "@nestjs/swagger";
|
|
||||||
import { CreateParentDto } from "./create_parent.dto";
|
|
||||||
|
|
||||||
export class UpdateParentsDto extends PartialType(CreateParentDto) {}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from "@nestjs/swagger";
|
|
||||||
import { CreateUserDto } from "./create_user.dto";
|
|
||||||
|
|
||||||
export class UpdateUserDto extends PartialType(CreateUserDto) {}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { GestionnairesController } from './gestionnaires.controller';
|
|
||||||
import { GestionnairesService } from './gestionnaires.service';
|
|
||||||
|
|
||||||
describe('GestionnairesController', () => {
|
|
||||||
let controller: GestionnairesController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [GestionnairesController],
|
|
||||||
providers: [GestionnairesService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
controller = module.get<GestionnairesController>(GestionnairesController);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(controller).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { GestionnairesService } from './gestionnaires.service';
|
|
||||||
import { GestionnairesController } from './gestionnaires.controller';
|
|
||||||
import { Users } from 'src/entities/users.entity';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [TypeOrmModule.forFeature([Users])],
|
|
||||||
controllers: [GestionnairesController],
|
|
||||||
providers: [GestionnairesService],
|
|
||||||
})
|
|
||||||
export class GestionnairesModule { }
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { GestionnairesService } from './gestionnaires.service';
|
|
||||||
|
|
||||||
describe('GestionnairesService', () => {
|
|
||||||
let service: GestionnairesService;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [GestionnairesService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
service = module.get<GestionnairesService>(GestionnairesService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
import {
|
|
||||||
ConflictException,
|
|
||||||
Injectable,
|
|
||||||
NotFoundException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
|
||||||
import { CreateGestionnaireDto } from '../dto/create_gestionnaire.dto';
|
|
||||||
import { UpdateGestionnaireDto } from '../dto/update_gestionnaire.dto';
|
|
||||||
import * as bcrypt from 'bcrypt';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class GestionnairesService {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Users)
|
|
||||||
private readonly gestionnaireRepository: Repository<Users>,
|
|
||||||
) { }
|
|
||||||
|
|
||||||
// Création d’un gestionnaire
|
|
||||||
async create(dto: CreateGestionnaireDto): Promise<Users> {
|
|
||||||
const exist = await this.gestionnaireRepository.findOneBy({ email: dto.email });
|
|
||||||
if (exist) throw new ConflictException('Email déjà utilisé');
|
|
||||||
|
|
||||||
const salt = await bcrypt.genSalt();
|
|
||||||
const hashedPassword = await bcrypt.hash(dto.password, salt);
|
|
||||||
|
|
||||||
const entity = this.gestionnaireRepository.create({
|
|
||||||
email: dto.email,
|
|
||||||
password: hashedPassword,
|
|
||||||
prenom: dto.prenom,
|
|
||||||
nom: dto.nom,
|
|
||||||
genre: dto.genre,
|
|
||||||
statut: dto.statut,
|
|
||||||
telephone: dto.telephone,
|
|
||||||
adresse: dto.adresse,
|
|
||||||
photo_url: dto.photo_url,
|
|
||||||
consentement_photo: dto.consentement_photo ?? false,
|
|
||||||
date_consentement_photo: dto.date_consentement_photo
|
|
||||||
? new Date(dto.date_consentement_photo)
|
|
||||||
: undefined,
|
|
||||||
changement_mdp_obligatoire: dto.changement_mdp_obligatoire ?? false,
|
|
||||||
role: RoleType.GESTIONNAIRE,
|
|
||||||
});
|
|
||||||
return this.gestionnaireRepository.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Liste des gestionnaires
|
|
||||||
async findAll(): Promise<Users[]> {
|
|
||||||
return this.gestionnaireRepository.find({ where: { role: RoleType.GESTIONNAIRE } });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Récupérer un gestionnaire par ID
|
|
||||||
async findOne(id: string): Promise<Users> {
|
|
||||||
const gestionnaire = await this.gestionnaireRepository.findOne({
|
|
||||||
where: { id, role: RoleType.GESTIONNAIRE },
|
|
||||||
});
|
|
||||||
if (!gestionnaire) throw new NotFoundException('Gestionnaire introuvable');
|
|
||||||
return gestionnaire;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour d’un gestionnaire
|
|
||||||
async update(id: string, dto: UpdateGestionnaireDto): Promise<Users> {
|
|
||||||
const gestionnaire = await this.findOne(id);
|
|
||||||
|
|
||||||
if (dto.password) {
|
|
||||||
const salt = await bcrypt.genSalt();
|
|
||||||
gestionnaire.password = await bcrypt.hash(dto.password, salt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dto.date_consentement_photo !== undefined) {
|
|
||||||
gestionnaire.date_consentement_photo = dto.date_consentement_photo
|
|
||||||
? new Date(dto.date_consentement_photo)
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { UserController } from './user.controller';
|
|
||||||
import { UserService } from './user.service';
|
|
||||||
|
|
||||||
describe('UserController', () => {
|
|
||||||
let controller: UserController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [UserController],
|
|
||||||
providers: [UserService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
controller = module.get<UserController>(UserController);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(controller).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,94 +0,0 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
|
||||||
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
||||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
|
||||||
import { Roles } from 'src/common/decorators/roles.decorator';
|
|
||||||
import { User } from 'src/common/decorators/user.decorator';
|
|
||||||
import { RoleType, Users } from 'src/entities/users.entity';
|
|
||||||
import { UserService } from './user.service';
|
|
||||||
import { CreateUserDto } from './dto/create_user.dto';
|
|
||||||
import { UpdateUserDto } from './dto/update_user.dto';
|
|
||||||
|
|
||||||
@ApiTags('Utilisateurs')
|
|
||||||
@ApiBearerAuth('access-token')
|
|
||||||
@UseGuards(AuthGuard)
|
|
||||||
@Controller('users')
|
|
||||||
export class UserController {
|
|
||||||
constructor(private readonly userService: UserService) { }
|
|
||||||
|
|
||||||
// Création d'un utilisateur (réservée aux super admins)
|
|
||||||
@Post()
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@ApiOperation({ summary: 'Créer un nouvel utilisateur (super admin seulement)' })
|
|
||||||
createUser(
|
|
||||||
@Body() dto: CreateUserDto,
|
|
||||||
@User() currentUser: Users
|
|
||||||
) {
|
|
||||||
return this.userService.createUser(dto, currentUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lister tous les utilisateurs (super_admin uniquement)
|
|
||||||
@Get()
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@ApiOperation({ summary: 'Lister tous les utilisateurs' })
|
|
||||||
findAll() {
|
|
||||||
return this.userService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Récupérer un utilisateur par son ID
|
|
||||||
@Get(':id')
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
|
||||||
@ApiOperation({ summary: 'Trouver un utilisateur par son id' })
|
|
||||||
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
|
||||||
findOne(@Param('id') id: string) {
|
|
||||||
return this.userService.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modifier un utilisateur (réservé super_admin)
|
|
||||||
@Patch(':id')
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@ApiOperation({ summary: 'Mettre à jour un utilisateur' })
|
|
||||||
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
|
||||||
updateUser(
|
|
||||||
@Param('id') id: string,
|
|
||||||
@Body() dto: UpdateUserDto,
|
|
||||||
@User() currentUser: Users
|
|
||||||
) {
|
|
||||||
return this.userService.updateUser(id, dto, currentUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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')
|
|
||||||
@Roles(RoleType.SUPER_ADMIN)
|
|
||||||
@ApiOperation({ summary: 'Supprimer un utilisateur' })
|
|
||||||
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
|
||||||
remove(@Param('id') id: string, @User() currentUser: Users) {
|
|
||||||
return this.userService.remove(id, currentUser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import { forwardRef, Module } from '@nestjs/common';
|
|
||||||
import { UserController } from './user.controller';
|
|
||||||
import { UserService } from './user.service';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { Users } from 'src/entities/users.entity';
|
|
||||||
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({
|
|
||||||
imports: [TypeOrmModule.forFeature(
|
|
||||||
[
|
|
||||||
Users,
|
|
||||||
Validation,
|
|
||||||
Parents,
|
|
||||||
AssistanteMaternelle,
|
|
||||||
]), forwardRef(() => AuthModule),
|
|
||||||
ParentsModule,
|
|
||||||
AssistantesMaternellesModule,
|
|
||||||
],
|
|
||||||
controllers: [UserController],
|
|
||||||
providers: [UserService],
|
|
||||||
exports: [UserService],
|
|
||||||
})
|
|
||||||
export class UserModule { }
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { UserService } from './user.service';
|
|
||||||
|
|
||||||
describe('UserService', () => {
|
|
||||||
let service: UserService;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [UserService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
service = module.get<UserService>(UserService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,233 +0,0 @@
|
|||||||
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
|
||||||
import { InjectRepository } from "@nestjs/typeorm";
|
|
||||||
import { RoleType, StatutUtilisateurType, Users } from "src/entities/users.entity";
|
|
||||||
import { In, Repository } from "typeorm";
|
|
||||||
import { CreateUserDto } from "./dto/create_user.dto";
|
|
||||||
import { UpdateUserDto } from "./dto/update_user.dto";
|
|
||||||
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()
|
|
||||||
export class UserService {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(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>
|
|
||||||
) { }
|
|
||||||
|
|
||||||
async createUser(dto: CreateUserDto, currentUser?: Users): Promise<Users> {
|
|
||||||
if (!dto.cguAccepted) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
'Vous devez accepter les CGU et la Politique de confidentialité pour créer un compte.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
if (dto.consentement_photo && dto.date_consentement_photo) {
|
|
||||||
const parsed = new Date(dto.date_consentement_photo);
|
|
||||||
if (!isNaN(parsed.getTime())) {
|
|
||||||
consentDate = parsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const salt = await bcrypt.genSalt();
|
|
||||||
const hashedPassword = await bcrypt.hash(dto.password, salt);
|
|
||||||
|
|
||||||
const entity = this.usersRepository.create({
|
|
||||||
email: dto.email,
|
|
||||||
password: hashedPassword,
|
|
||||||
prenom: dto.prenom,
|
|
||||||
nom: dto.nom,
|
|
||||||
role,
|
|
||||||
statut,
|
|
||||||
genre: dto.genre,
|
|
||||||
telephone: dto.telephone,
|
|
||||||
ville: dto.ville,
|
|
||||||
code_postal: dto.code_postal,
|
|
||||||
adresse: dto.adresse,
|
|
||||||
photo_url: dto.photo_url,
|
|
||||||
consentement_photo: dto.consentement_photo ?? false,
|
|
||||||
date_consentement_photo: consentDate,
|
|
||||||
changement_mdp_obligatoire:
|
|
||||||
role === RoleType.ADMINISTRATEUR || role === RoleType.GESTIONNAIRE
|
|
||||||
? true
|
|
||||||
: dto.changement_mdp_obligatoire ?? false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const saved = await this.usersRepository.save(entity);
|
|
||||||
return this.findOne(saved.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(): Promise<Users[]> {
|
|
||||||
return this.usersRepository.find();
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOneBy(where: Partial<Users>): Promise<Users | null> {
|
|
||||||
return this.usersRepository.findOne({ where });
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOne(id: string): Promise<Users> {
|
|
||||||
const user = await this.usersRepository.findOne({ where: { id } });
|
|
||||||
if (!user) {
|
|
||||||
throw new NotFoundException('Utilisateur introuvable');
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findByEmailOrNull(email: string): Promise<Users | null> {
|
|
||||||
return this.usersRepository.findOne({ where: { email } });
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateUser(id: string, dto: UpdateUserDto, currentUser: Users): Promise<Users> {
|
|
||||||
const user = await this.findOne(id);
|
|
||||||
|
|
||||||
// Interdire changement de rôle si pas super admin
|
|
||||||
if (dto.role && currentUser.role !== RoleType.SUPER_ADMIN) {
|
|
||||||
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
|
|
||||||
if (dto.password) {
|
|
||||||
const salt = await bcrypt.genSalt();
|
|
||||||
user.password = await bcrypt.hash(dto.password, salt);
|
|
||||||
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
|
|
||||||
if (dto.date_consentement_photo !== undefined) {
|
|
||||||
user.date_consentement_photo = dto.date_consentement_photo
|
|
||||||
? new Date(dto.date_consentement_photo)
|
|
||||||
: undefined;
|
|
||||||
delete (dto as any).date_consentement_photo;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.assign(user, dto);
|
|
||||||
return this.usersRepository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valider un compte utilisateur
|
|
||||||
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);
|
|
||||||
if (result.affected === 0) {
|
|
||||||
throw new NotFoundException('Utilisateur introuvable');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
src/types/express/index.d.ts
vendored
11
src/types/express/index.d.ts
vendored
@ -1,11 +0,0 @@
|
|||||||
import { Users } from 'src/entities/users.entity';
|
|
||||||
|
|
||||||
declare module 'express-serve-static-core' {
|
|
||||||
interface Request {
|
|
||||||
user?: Users & {
|
|
||||||
sub?: string;
|
|
||||||
email?: string;
|
|
||||||
role?: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -20,7 +20,6 @@
|
|||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"strictBindCallApply": false,
|
"strictBindCallApply": false,
|
||||||
"noFallthroughCasesInSwitch": false,
|
"noFallthroughCasesInSwitch": false
|
||||||
"typeRoots": ["./node_modules/@types", "./src/types"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user