Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bbdab03d0 | ||
|
|
7f78617561 | ||
|
|
7707b99773 | ||
|
|
760f4feca3 | ||
|
|
03712bd99b | ||
|
|
1496f7f174 | ||
|
|
acb602643a | ||
|
|
0772f83369 | ||
|
|
42d147c273 | ||
|
|
df56ba11df | ||
|
|
bbdacd68aa | ||
|
|
7f831f363e | ||
|
|
009d42ece8 | ||
|
|
e6d3c41ecc | ||
|
|
c7ac3d9ebe | ||
|
|
c8b8ad9318 | ||
|
|
482040ba55 | ||
|
|
2bcb0b1e54 | ||
|
|
30e72242a8 | ||
|
|
aaf7070757 | ||
|
|
f4c211e0dd | ||
|
|
9519fafe3a | ||
|
|
9321430818 |
1
.gitignore
vendored
@ -52,4 +52,3 @@ Xcf/**
|
||||
# Release notes
|
||||
CHANGELOG.md
|
||||
Ressources/
|
||||
.gitea-token
|
||||
|
||||
BIN
Archives/ChatGPT Image 25 avr. 2025, 16_45_30.png
Normal file
|
After Width: | Height: | Size: 2.3 MiB |
BIN
Archives/ChatGPT Image 30 avr. 2025, 11_48_00.png
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
Archives/ChatGPT Image 30 avr. 2025, 11_48_14.png
Normal file
|
After Width: | Height: | Size: 2.2 MiB |
BIN
Archives/Cinq Styles de _P'titsPas_.png
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
Archives/P'tisPas_logo.png
Normal file
|
After Width: | Height: | Size: 2.2 MiB |
BIN
Archives/P'tisPas_logo_trans.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
Archives/P'titsPas et pierres colorées.png
Normal file
|
After Width: | Height: | Size: 2.3 MiB |
BIN
Archives/P'titsPas_icone.png
Normal file
|
After Width: | Height: | Size: 157 KiB |
BIN
Archives/Pas à Pas en Couleurs tordu.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
Archives/Pas à Pas en Pastel encre.png
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
Archives/Taches_encres_01.png
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
BIN
Archives/Taches_encres_02.png
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
Archives/Taches_encres_03.png
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
BIN
Archives/champs_login.png
Normal file
|
After Width: | Height: | Size: 2.2 MiB |
BIN
Archives/champs_login_2.png
Normal file
|
After Width: | Height: | Size: 2.3 MiB |
BIN
Archives/echantillons pierres.png
Normal file
|
After Width: | Height: | Size: 2.8 MiB |
BIN
Archives/icon.png
Normal file
|
After Width: | Height: | Size: 157 KiB |
BIN
Archives/logo.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
Archives/logo02.png
Normal file
|
After Width: | Height: | Size: 662 KiB |
BIN
Archives/logo03.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
Archives/logo04.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
Archives/page_login.png
Normal file
|
After Width: | Height: | Size: 366 KiB |
BIN
Archives/page_login_2.png
Normal file
|
After Width: | Height: | Size: 501 KiB |
BIN
Archives/page_login_3.png
Normal file
|
After Width: | Height: | Size: 563 KiB |
BIN
Archives/page_login_4.1.png
Normal file
|
After Width: | Height: | Size: 498 KiB |
BIN
Archives/paper.png
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
Archives/paper2.png
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
BIN
Archives/pierres.png
Normal file
|
After Width: | Height: | Size: 164 KiB |
BIN
Archives/propositions.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
Xcf/P'tisPas_logo_trans.xcf
Normal file
BIN
Xcf/P'titsPas et pierres colorées.xcf
Normal file
BIN
Xcf/P'titsPas_icone.xcf
Normal file
BIN
Xcf/P'titsPas_logo.xcf
Normal file
BIN
Xcf/page_login.xcf
Normal file
@ -1,87 +0,0 @@
|
||||
# 📜 API Contracts - PtitsPas
|
||||
|
||||
Ce dossier contient les **contrats d'API** qui définissent les interfaces entre les différentes couches de l'application.
|
||||
|
||||
## 🎯 Objectif
|
||||
|
||||
Garantir que **Frontend**, **Backend** et **Database** respectent des contrats stricts, permettant de les rendre **interchangeables** sans casser l'application.
|
||||
|
||||
---
|
||||
|
||||
## 📁 Structure
|
||||
|
||||
```
|
||||
api-contracts/
|
||||
├── frontend-backend/ # Contrat Frontend ↔ Backend (HTTP REST)
|
||||
│ ├── openapi.yaml # Spécification OpenAPI 3.0 (source de vérité)
|
||||
│ └── generated/ # Code généré automatiquement
|
||||
│ ├── dart/ # Client API pour Flutter
|
||||
│ └── typescript/ # Types pour NestJS
|
||||
│
|
||||
└── backend-database/ # Contrat Backend ↔ Database (ORM/SQL)
|
||||
├── schema.prisma # Schéma Prisma (ou TypeORM entities)
|
||||
└── migrations/ # Migrations SQL versionnées
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Workflow de Génération
|
||||
|
||||
### 1. Frontend ↔ Backend
|
||||
|
||||
**Source de vérité :** `frontend-backend/openapi.yaml`
|
||||
|
||||
**Génération du client Dart (Flutter) :**
|
||||
```bash
|
||||
cd api-contracts/frontend-backend
|
||||
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
|
||||
-i /local/openapi.yaml \
|
||||
-g dart-dio \
|
||||
-o /local/generated/dart
|
||||
```
|
||||
|
||||
**Génération des types TypeScript (NestJS) :**
|
||||
```bash
|
||||
cd api-contracts/frontend-backend
|
||||
npx openapi-typescript openapi.yaml --output generated/typescript/api.types.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2. Backend ↔ Database
|
||||
|
||||
**Source de vérité :** `backend-database/schema.prisma`
|
||||
|
||||
**Génération du client Prisma :**
|
||||
```bash
|
||||
cd api-contracts/backend-database
|
||||
npx prisma generate
|
||||
```
|
||||
|
||||
**Génération des migrations SQL :**
|
||||
```bash
|
||||
cd api-contracts/backend-database
|
||||
npx prisma migrate dev --name <nom_migration>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ Avantages
|
||||
|
||||
- **Frontend interchangeable** : React, Vue, Angular → il suffit de régénérer le client API
|
||||
- **Backend interchangeable** : Python, Go, Java → tant qu'il respecte `openapi.yaml`
|
||||
- **Database read-only en prod** : User PostgreSQL `app_user` (pas de DDL)
|
||||
- **Cohérence garantie** : Types générés = pas d'erreur de typage
|
||||
- **Documentation auto** : OpenAPI = documentation interactive (Swagger UI)
|
||||
|
||||
---
|
||||
|
||||
## 📚 Documentation
|
||||
|
||||
- [OpenAPI 3.0 Spec](https://swagger.io/specification/)
|
||||
- [Prisma Schema](https://www.prisma.io/docs/concepts/components/prisma-schema)
|
||||
- [openapi-generator](https://openapi-generator.tech/)
|
||||
- [openapi-typescript](https://github.com/drwpow/openapi-typescript)
|
||||
|
||||
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
# 💾 Backend ↔ Database Contract
|
||||
|
||||
Ce dossier contient le **contrat de données** entre le Backend et la Base de Données.
|
||||
|
||||
## 📋 Contenu
|
||||
|
||||
- **`schema.prisma`** : Schéma de base de données (à créer)
|
||||
- **`migrations/`** : Migrations SQL versionnées (actuellement dans `/database/migrations/`)
|
||||
|
||||
## 🔄 Migration Future
|
||||
|
||||
À terme, les migrations SQL de `/database/migrations/` seront gérées ici avec Prisma :
|
||||
|
||||
```bash
|
||||
# Générer une migration
|
||||
npx prisma migrate dev --name add_user_phone
|
||||
|
||||
# Appliquer en production
|
||||
npx prisma migrate deploy
|
||||
```
|
||||
|
||||
## 📚 Référence
|
||||
|
||||
- [Prisma Migrate](https://www.prisma.io/docs/concepts/components/prisma-migrate)
|
||||
|
||||
|
||||
|
||||
@ -1,179 +0,0 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: PtitsPas API
|
||||
version: 1.0.0
|
||||
description: |
|
||||
API REST pour l'application PtitsPas.
|
||||
Ce contrat définit l'interface entre le Frontend (Flutter) et le Backend (NestJS).
|
||||
contact:
|
||||
name: PtitsPas Team
|
||||
email: admin@ptits-pas.fr
|
||||
|
||||
servers:
|
||||
- url: https://app.ptits-pas.fr/api
|
||||
description: Production
|
||||
- url: http://localhost:3000/api
|
||||
description: Développement local
|
||||
|
||||
paths:
|
||||
/auth/login:
|
||||
post:
|
||||
summary: Authentification utilisateur
|
||||
operationId: loginUser
|
||||
tags:
|
||||
- Authentication
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- email
|
||||
- password
|
||||
properties:
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
example: admin@ptits-pas.fr
|
||||
password:
|
||||
type: string
|
||||
format: password
|
||||
example: "4dm1n1strateur"
|
||||
responses:
|
||||
'200':
|
||||
description: Authentification réussie
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
access_token:
|
||||
type: string
|
||||
description: Token JWT d'accès
|
||||
refresh_token:
|
||||
type: string
|
||||
description: Token JWT de rafraîchissement
|
||||
user:
|
||||
$ref: '#/components/schemas/User'
|
||||
'401':
|
||||
description: Identifiants invalides
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
|
||||
/users:
|
||||
get:
|
||||
summary: Liste des utilisateurs
|
||||
operationId: listUsers
|
||||
tags:
|
||||
- Users
|
||||
security:
|
||||
- bearerAuth: []
|
||||
parameters:
|
||||
- name: role
|
||||
in: query
|
||||
schema:
|
||||
$ref: '#/components/schemas/RoleType'
|
||||
- name: statut
|
||||
in: query
|
||||
schema:
|
||||
$ref: '#/components/schemas/StatutUtilisateurType'
|
||||
responses:
|
||||
'200':
|
||||
description: Liste des utilisateurs
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/User'
|
||||
'401':
|
||||
description: Non authentifié
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
|
||||
components:
|
||||
schemas:
|
||||
User:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- email
|
||||
- role
|
||||
- statut
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
example: "550e8400-e29b-41d4-a716-446655440000"
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
example: "parent@ptits-pas.fr"
|
||||
prenom:
|
||||
type: string
|
||||
example: "Jean"
|
||||
nom:
|
||||
type: string
|
||||
example: "Dupont"
|
||||
role:
|
||||
$ref: '#/components/schemas/RoleType'
|
||||
statut:
|
||||
$ref: '#/components/schemas/StatutUtilisateurType'
|
||||
telephone:
|
||||
type: string
|
||||
example: "0612345678"
|
||||
adresse:
|
||||
type: string
|
||||
photo_url:
|
||||
type: string
|
||||
format: uri
|
||||
cree_le:
|
||||
type: string
|
||||
format: date-time
|
||||
|
||||
RoleType:
|
||||
type: string
|
||||
enum:
|
||||
- parent
|
||||
- assistante_maternelle
|
||||
- gestionnaire
|
||||
- administrateur
|
||||
- super_admin
|
||||
|
||||
StatutUtilisateurType:
|
||||
type: string
|
||||
enum:
|
||||
- en_attente
|
||||
- actif
|
||||
- suspendu
|
||||
|
||||
Error:
|
||||
type: object
|
||||
required:
|
||||
- message
|
||||
- statusCode
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
example: "Identifiants invalides"
|
||||
statusCode:
|
||||
type: integer
|
||||
example: 401
|
||||
error:
|
||||
type: string
|
||||
example: "Unauthorized"
|
||||
|
||||
securitySchemes:
|
||||
bearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
description: Token JWT obtenu via /auth/login
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
64
backend/.gitignore
vendored
@ -1,64 +0,0 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
.env
|
||||
|
||||
|
||||
# Tests bdd
|
||||
.vscode/
|
||||
BDD.sql
|
||||
migrations/
|
||||
src/seed/
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
@ -1,42 +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
|
||||
|
||||
# Créer le dossier uploads et donner les permissions
|
||||
RUN mkdir -p /app/uploads/photos && chown -R nestjs:nodejs /app/uploads
|
||||
|
||||
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,158 +0,0 @@
|
||||
# P'titsPas API Backend ✨
|
||||
|
||||
Ce dépôt contient le code source de l'API backend pour la plateforme **P'titsPas**. L'API est construite avec NestJS et est responsable de toute la logique métier, de la gestion des données et de l'authentification des utilisateurs.
|
||||
|
||||
---
|
||||
|
||||
## 📚 Table des matières
|
||||
|
||||
- [Technologies utilisées](#-technologies-utilisées)
|
||||
- [Prérequis](#-prérequis)
|
||||
- [Installation](#-installation)
|
||||
- [Lancement de l'application](#-lancement-de-lapplication)
|
||||
- [Scripts principaux](#-scripts-principaux)
|
||||
- [Tests](#-tests)
|
||||
- [Gestion des migrations](#-gestion-des-migrations)
|
||||
- [Documentation de l'API](#-documentation-de-lapi)
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Technologies utilisées
|
||||
|
||||
- **Framework**: [NestJS](https://nestjs.com/) (TypeScript)
|
||||
- **Base de données**: [PostgreSQL](https://www.postgresql.org/)
|
||||
- **ORM**: [TypeORM](https://typeorm.io/)
|
||||
- **Authentification**: JWT avec [Passport.js](http://www.passportjs.org/)
|
||||
- **Stockage Fichiers**: [MinIO](https://min.io/) (Compatible S3)
|
||||
- **Tâches Asynchrones**: [Redis](https://redis.io/) avec [BullMQ](https://bullmq.io/)
|
||||
- **Conteneurisation**: [Docker](https://www.docker.com/)
|
||||
|
||||
---
|
||||
|
||||
## 📋 Prérequis
|
||||
|
||||
Avant de commencer, assurez-vous d'avoir installé les outils suivants sur votre machine :
|
||||
|
||||
- [Node.js](https://nodejs.org/) (v18 ou supérieure)
|
||||
- [npm](https://www.npmjs.com/) ou [pnpm](https://pnpm.io/)
|
||||
- [Docker](https://www.docker.com/products/docker-desktop/) et Docker Compose
|
||||
- [Git](https://git-scm.com/)
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Installation
|
||||
|
||||
1. **Clonez le dépôt :**
|
||||
|
||||
```bash
|
||||
git clone https://github.com/votre-username/ptitspas-backend.git
|
||||
cd ptitspas-backend
|
||||
```
|
||||
|
||||
2. **Créez le fichier d'environnement :**
|
||||
Copiez le fichier d'exemple `.env.example` et renommez-le en `.env`. Ce fichier est ignoré par Git et contiendra vos secrets locaux.
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
➡️ **Important :** Ouvrez le fichier `.env` et remplissez les variables (identifiants de la base de données, secrets JWT, etc.).
|
||||
|
||||
3. **Installez les dépendances du projet :**
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ▶️ Lancement de l'application
|
||||
|
||||
### Méthode recommandée : avec Docker
|
||||
|
||||
Cette méthode lance l'ensemble des services nécessaires (API, base de données, MinIO, Redis) dans des conteneurs isolés.
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
L'API sera accessible à l'adresse `http://localhost:3000` (ou le port que vous avez configuré dans votre `.env`).
|
||||
|
||||
### Méthode locale (pour le développement)
|
||||
|
||||
Cette méthode ne lance que le serveur NestJS. Assurez-vous que les autres services (PostgreSQL, Redis, etc.) sont déjà en cours d'exécution (par exemple, via Docker).
|
||||
|
||||
```
|
||||
npm run start:dev
|
||||
```
|
||||
|
||||
Le serveur redémarrera automatiquement à chaque modification de fichier.
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Scripts principaux
|
||||
|
||||
| Commande | Description |
|
||||
| :------------------ | :-------------------------------------------------------------------- |
|
||||
| `npm run start:dev` | Lance le serveur en mode développement avec rechargement automatique. |
|
||||
| `npm run build` | Compile le projet TypeScript en JavaScript. |
|
||||
| `npm start` | Lance l'application depuis les fichiers compilés (mode production). |
|
||||
| `npm run lint` | Analyse le code pour détecter les erreurs de style et de syntaxe. |
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Tests
|
||||
|
||||
Pour lancer les tests, utilisez les commandes suivantes :
|
||||
|
||||
| Commande | Description |
|
||||
| :----------------- | :--------------------------------------------------------------- |
|
||||
| `npm test` | Lance les tests unitaires. |
|
||||
| `npm run test:e2e` | Lance les tests de bout en bout (end-to-end). |
|
||||
| `npm run test:cov` | Lance tous les tests et génère un rapport de couverture de code. |
|
||||
|
||||
---
|
||||
|
||||
## 🗄️ Gestion des migrations
|
||||
|
||||
La structure de la base de données est gérée par des fichiers de migration TypeORM.
|
||||
|
||||
1. **Générer une nouvelle migration :**
|
||||
Après avoir modifié une entité TypeORM, générez automatiquement le fichier de migration correspondant.
|
||||
|
||||
```bash
|
||||
npm run migration:generate -- src/database/migrations/NomDeLaMigration
|
||||
```
|
||||
|
||||
2. **Appliquer les migrations :**
|
||||
Pour mettre à jour le schéma de votre base de données avec les nouvelles migrations.
|
||||
```bash
|
||||
npm run migration:run
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📖 Documentation de l'API
|
||||
|
||||
Une fois l'application lancée, la documentation de l'API générée avec **Swagger (OpenAPI)** est disponible à l'adresse suivante :
|
||||
|
||||
➡️ **[http://localhost:3000/api-docs](http://localhost:3000/api-docs)**
|
||||
|
||||
Cette interface vous permet d'explorer et de tester toutes les routes de l'API directement depuis votre navigateur.
|
||||
|
||||
Excellente idée. C'est un élément crucial qui définit les droits et les devoirs liés à votre code.
|
||||
|
||||
En me basant sur la section `10.5 Propriété intellectuelle et licence de l’application` de votre cahier des charges, j'ai rédigé une section "Licence" qui reflète précisément le statut propriétaire de votre projet.
|
||||
|
||||
Voici le `README.md` complet et mis à jour.
|
||||
|
||||
---
|
||||
|
||||
## 📜 Licence
|
||||
|
||||
Ce projet est distribué sous une **licence propriétaire**.
|
||||
|
||||
Le code source, la marque "P'titsPas" et la documentation associée sont la propriété exclusive de l'éditeur, Julien MARTIN.
|
||||
|
||||
Toute reproduction, distribution, modification ou utilisation du code source est strictement interdite sans un accord écrit préalable de l'auteur. Les clients et partenaires autorisés disposent d'une licence d'utilisation non-exclusive et non-transférable, conformément aux termes de leur contrat.
|
||||
|
||||
Pour toute question relative à l'utilisation ou à l'acquisition d'une licence, veuillez contacter l'auteur.
|
||||
@ -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
|
||||
@ -1,34 +0,0 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['eslint.config.mjs'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
eslintPluginPrettierRecommended,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest,
|
||||
},
|
||||
sourceType: 'commonjs',
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'warn',
|
||||
'@typescript-eslint/no-unsafe-argument': 'warn'
|
||||
},
|
||||
},
|
||||
);
|
||||
@ -1,8 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
11513
backend/package-lock.json
generated
@ -1,95 +1,36 @@
|
||||
{
|
||||
"name": "ptitspas-ynov-back",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"name": "petitspas-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Backend pour l'application P'titsPas",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"typeorm": "typeorm-ts-node-commonjs",
|
||||
"migration:run": "npm run typeorm migration:run",
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
"init-admin": "ts-node src/scripts/initAdmin.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.1.6",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/jwt": "^11.0.0",
|
||||
"@nestjs/mapped-types": "^2.1.0",
|
||||
"@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",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"nodemailer": "^6.9.16",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"pg": "^8.16.3",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"typeorm": "^0.3.26"
|
||||
"@nestjs/common": "^11.1.0",
|
||||
"@prisma/client": "^6.7.0",
|
||||
"@types/jsonwebtoken": "^9.0.9",
|
||||
"bcrypt": "^5.1.1",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"helmet": "^7.1.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"morgan": "^1.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@nestjs/cli": "^11.0.10",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@types/bcrypt": "^6.0.0",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/nodemailer": "^6.4.16",
|
||||
"@types/passport-jwt": "^4.0.1",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"globals": "^16.0.0",
|
||||
"jest": "^30.0.0",
|
||||
"prettier": "^3.4.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.2.5",
|
||||
"ts-loader": "^9.5.2",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/helmet": "^4.0.0",
|
||||
"@types/morgan": "^1.9.9",
|
||||
"@types/node": "^20.11.19",
|
||||
"prisma": "^6.7.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.20.0"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
108
backend/prisma/schema.prisma
Normal file
@ -0,0 +1,108 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// Modèle pour les parents
|
||||
model Parent {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
password String
|
||||
firstName String
|
||||
lastName String
|
||||
phoneNumber String?
|
||||
address String?
|
||||
status AccountStatus @default(PENDING)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
children Child[]
|
||||
contracts Contract[]
|
||||
}
|
||||
|
||||
// Modèle pour les enfants
|
||||
model Child {
|
||||
id String @id @default(uuid())
|
||||
firstName String
|
||||
dateOfBirth DateTime
|
||||
photoUrl String?
|
||||
photoConsent Boolean @default(false)
|
||||
isMultiple Boolean @default(false)
|
||||
isUnborn Boolean @default(false)
|
||||
parentId String
|
||||
parent Parent @relation(fields: [parentId], references: [id])
|
||||
contracts Contract[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
// Modèle pour les contrats
|
||||
model Contract {
|
||||
id String @id @default(uuid())
|
||||
parentId String
|
||||
childId String
|
||||
startDate DateTime
|
||||
endDate DateTime?
|
||||
status ContractStatus @default(ACTIVE)
|
||||
parent Parent @relation(fields: [parentId], references: [id])
|
||||
child Child @relation(fields: [childId], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
// Modèle pour les thèmes
|
||||
model Theme {
|
||||
id String @id @default(uuid())
|
||||
name String @unique
|
||||
primaryColor String
|
||||
secondaryColor String
|
||||
backgroundColor String
|
||||
textColor String
|
||||
isActive Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
appSettings AppSettings[]
|
||||
}
|
||||
|
||||
// Modèle pour les paramètres de l'application
|
||||
model AppSettings {
|
||||
id String @id @default(uuid())
|
||||
currentThemeId String
|
||||
currentTheme Theme @relation(fields: [currentThemeId], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([currentThemeId])
|
||||
}
|
||||
|
||||
// Modèle pour les administrateurs
|
||||
model Admin {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
password String
|
||||
firstName String
|
||||
lastName String
|
||||
passwordChanged Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
// Enums
|
||||
enum AccountStatus {
|
||||
PENDING
|
||||
VALIDATED
|
||||
REJECTED
|
||||
SUSPENDED
|
||||
}
|
||||
|
||||
enum ContractStatus {
|
||||
ACTIVE
|
||||
ENDED
|
||||
CANCELLED
|
||||
}
|
||||
18
backend/src/admin/admin.controller.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Controller, Post, Body, UseGuards, Req } from '@nestjs/common';
|
||||
import { AdminService } from './admin.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
|
||||
@Controller('admin')
|
||||
export class AdminController {
|
||||
constructor(private readonly adminService: AdminService) {}
|
||||
|
||||
@Post('change-password')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
async changePassword(
|
||||
@Req() req,
|
||||
@Body('oldPassword') oldPassword: string,
|
||||
@Body('newPassword') newPassword: string,
|
||||
) {
|
||||
return this.adminService.changePassword(req.user.id, oldPassword, newPassword);
|
||||
}
|
||||
}
|
||||
18
backend/src/admin/admin.module.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AdminController } from './admin.controller';
|
||||
import { AdminService } from './admin.service';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PrismaModule,
|
||||
JwtModule.register({
|
||||
secret: process.env.JWT_SECRET,
|
||||
signOptions: { expiresIn: '1d' },
|
||||
}),
|
||||
],
|
||||
controllers: [AdminController],
|
||||
providers: [AdminService],
|
||||
})
|
||||
export class AdminModule {}
|
||||
40
backend/src/admin/admin.service.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
|
||||
@Injectable()
|
||||
export class AdminService {
|
||||
constructor(
|
||||
private prisma: PrismaService,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
async changePassword(adminId: string, oldPassword: string, newPassword: string) {
|
||||
// Récupérer l'administrateur
|
||||
const admin = await this.prisma.admin.findUnique({
|
||||
where: { id: adminId },
|
||||
});
|
||||
|
||||
if (!admin) {
|
||||
throw new UnauthorizedException('Administrateur non trouvé');
|
||||
}
|
||||
|
||||
// Vérifier l'ancien mot de passe
|
||||
const isPasswordValid = await bcrypt.compare(oldPassword, admin.password);
|
||||
if (!isPasswordValid) {
|
||||
throw new UnauthorizedException('Ancien mot de passe incorrect');
|
||||
}
|
||||
|
||||
// Hasher le nouveau mot de passe
|
||||
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||
|
||||
// Mettre à jour le mot de passe
|
||||
await this.prisma.admin.update({
|
||||
where: { id: adminId },
|
||||
data: { password: hashedPassword },
|
||||
});
|
||||
|
||||
return { message: 'Mot de passe modifié avec succès' };
|
||||
}
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,17 +0,0 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getOverView() {
|
||||
return this.appService.getOverView();
|
||||
}
|
||||
|
||||
@Get('hello')
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
@ -1,71 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AppController } from './app.controller';
|
||||
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';
|
||||
import { AppConfigModule } from './modules/config/config.module';
|
||||
import { DocumentsLegauxModule } from './modules/documents-legaux';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { AdminModule } from './admin/admin.module';
|
||||
|
||||
@Module({
|
||||
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,
|
||||
PrismaModule,
|
||||
AuthModule,
|
||||
AppConfigModule,
|
||||
DocumentsLegauxModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
AppService,
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
useClass: SentryGlobalFilter
|
||||
},
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
useClass: AllExceptionsFilter,
|
||||
}
|
||||
|
||||
AdminModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
@ -1,62 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello Test!!!';
|
||||
}
|
||||
|
||||
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(),
|
||||
});
|
||||
72
backend/src/controllers/theme.controller.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { ThemeService, ThemeData } from '../services/theme.service';
|
||||
|
||||
export class ThemeController {
|
||||
// Créer un nouveau thème
|
||||
static async createTheme(req: Request, res: Response) {
|
||||
try {
|
||||
const themeData: ThemeData = req.body;
|
||||
const theme = await ThemeService.createTheme(themeData);
|
||||
res.status(201).json(theme);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Erreur lors de la création du thème' });
|
||||
}
|
||||
}
|
||||
|
||||
// Récupérer tous les thèmes
|
||||
static async getAllThemes(req: Request, res: Response) {
|
||||
try {
|
||||
const themes = await ThemeService.getAllThemes();
|
||||
res.json(themes);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Erreur lors de la récupération des thèmes' });
|
||||
}
|
||||
}
|
||||
|
||||
// Récupérer le thème actif
|
||||
static async getActiveTheme(req: Request, res: Response) {
|
||||
try {
|
||||
const theme = await ThemeService.getActiveTheme();
|
||||
if (!theme) {
|
||||
return res.status(404).json({ error: 'Aucun thème actif trouvé' });
|
||||
}
|
||||
res.json(theme);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Erreur lors de la récupération du thème actif' });
|
||||
}
|
||||
}
|
||||
|
||||
// Activer un thème
|
||||
static async activateTheme(req: Request, res: Response) {
|
||||
try {
|
||||
const { themeId } = req.params;
|
||||
const theme = await ThemeService.activateTheme(themeId);
|
||||
res.json(theme);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Erreur lors de l\'activation du thème' });
|
||||
}
|
||||
}
|
||||
|
||||
// Mettre à jour un thème
|
||||
static async updateTheme(req: Request, res: Response) {
|
||||
try {
|
||||
const { themeId } = req.params;
|
||||
const themeData: Partial<ThemeData> = req.body;
|
||||
const theme = await ThemeService.updateTheme(themeId, themeData);
|
||||
res.json(theme);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Erreur lors de la mise à jour du thème' });
|
||||
}
|
||||
}
|
||||
|
||||
// Supprimer un thème
|
||||
static async deleteTheme(req: Request, res: Response) {
|
||||
try {
|
||||
const { themeId } = req.params;
|
||||
await ThemeService.deleteTheme(themeId);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Erreur lors de la suppression du thème' });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
CreateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Users } from './users.entity';
|
||||
import { DocumentLegal } from './document-legal.entity';
|
||||
|
||||
@Entity('acceptations_documents')
|
||||
export class AcceptationDocument {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@ManyToOne(() => Users, { nullable: false, onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_utilisateur' })
|
||||
utilisateur: Users;
|
||||
|
||||
@ManyToOne(() => DocumentLegal, { nullable: true })
|
||||
@JoinColumn({ name: 'id_document' })
|
||||
document: DocumentLegal | null;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
type_document: 'cgu' | 'privacy';
|
||||
|
||||
@Column({ type: 'integer', nullable: false })
|
||||
version_document: number;
|
||||
|
||||
@CreateDateColumn({ name: 'accepte_le', type: 'timestamptz' })
|
||||
accepteLe: Date;
|
||||
|
||||
@Column({ type: 'inet', nullable: true })
|
||||
ip_address: string | null;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
user_agent: string | null;
|
||||
}
|
||||
|
||||
@ -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,39 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Users } from './users.entity';
|
||||
|
||||
@Entity('configuration')
|
||||
export class Configuration {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100, unique: true, nullable: false })
|
||||
cle: string;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
valeur: string | null;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
type: 'string' | 'number' | 'boolean' | 'json' | 'encrypted';
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||
categorie: 'email' | 'app' | 'security' | null;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
description: string | null;
|
||||
|
||||
@UpdateDateColumn({ name: 'modifie_le' })
|
||||
modifieLe: Date;
|
||||
|
||||
@ManyToOne(() => Users, { nullable: true })
|
||||
@JoinColumn({ name: 'modifie_par' })
|
||||
modifiePar: Users | null;
|
||||
}
|
||||
|
||||
@ -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,44 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
CreateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Users } from './users.entity';
|
||||
|
||||
@Entity('documents_legaux')
|
||||
export class DocumentLegal {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 50, nullable: false })
|
||||
type: 'cgu' | 'privacy';
|
||||
|
||||
@Column({ type: 'integer', nullable: false })
|
||||
version: number;
|
||||
|
||||
@Column({ type: 'varchar', length: 255, nullable: false })
|
||||
fichier_nom: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 500, nullable: false })
|
||||
fichier_path: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 64, nullable: false })
|
||||
fichier_hash: string;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
actif: boolean;
|
||||
|
||||
@ManyToOne(() => Users, { nullable: true })
|
||||
@JoinColumn({ name: 'televerse_par' })
|
||||
televersePar: Users | null;
|
||||
|
||||
@CreateDateColumn({ name: 'televerse_le', type: 'timestamptz' })
|
||||
televerseLe: Date;
|
||||
|
||||
@Column({ name: 'active_le', type: 'timestamptz', nullable: true })
|
||||
activeLe: Date | null;
|
||||
}
|
||||
|
||||
@ -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', nullable: true })
|
||||
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({ 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: 'token_creation_mdp', length: 255 })
|
||||
token_creation_mdp?: string;
|
||||
|
||||
@Column({ type: 'timestamptz', nullable: true, name: 'token_creation_mdp_expire_le' })
|
||||
token_creation_mdp_expire_le?: Date;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
28
backend/src/index.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import helmet from 'helmet';
|
||||
import morgan from 'morgan';
|
||||
import themeRoutes from './routes/theme.routes';
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(helmet());
|
||||
app.use(morgan('dev'));
|
||||
app.use(express.json());
|
||||
|
||||
// Routes
|
||||
app.use('/api/themes', themeRoutes);
|
||||
|
||||
// Gestion des erreurs
|
||||
app.use((err: Error, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
console.error(err.stack);
|
||||
res.status(500).json({ error: 'Une erreur est survenue' });
|
||||
});
|
||||
|
||||
// Démarrage du serveur
|
||||
app.listen(port, () => {
|
||||
console.log(`Serveur démarré sur le port ${port}`);
|
||||
});
|
||||
@ -1,59 +0,0 @@
|
||||
import { NestFactory, Reflector } from '@nestjs/core';
|
||||
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() {
|
||||
const app = await NestFactory.create(AppModule,
|
||||
{ logger: ['error', 'warn', 'log', 'debug', 'verbose'] });
|
||||
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().catch((err) => {
|
||||
console.error('❌ Error starting the application:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
@ -1,232 +0,0 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Patch,
|
||||
Post,
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
Request,
|
||||
HttpStatus,
|
||||
HttpException,
|
||||
} from '@nestjs/common';
|
||||
import { AppConfigService } from './config.service';
|
||||
import { UpdateConfigDto } from './dto/update-config.dto';
|
||||
import { TestSmtpDto } from './dto/test-smtp.dto';
|
||||
|
||||
@Controller('configuration')
|
||||
export class ConfigController {
|
||||
constructor(private readonly configService: AppConfigService) {}
|
||||
|
||||
/**
|
||||
* Vérifier si la configuration initiale est terminée
|
||||
* GET /api/v1/configuration/setup/status
|
||||
*/
|
||||
@Get('setup/status')
|
||||
async getSetupStatus() {
|
||||
try {
|
||||
const isCompleted = this.configService.isSetupCompleted();
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
setupCompleted: isCompleted,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Erreur lors de la vérification du statut de configuration',
|
||||
error: error.message,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marquer la configuration initiale comme terminée
|
||||
* POST /api/v1/configuration/setup/complete
|
||||
*/
|
||||
@Post('setup/complete')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin')
|
||||
async completeSetup(@Request() req: any) {
|
||||
try {
|
||||
// TODO: Récupérer l'ID utilisateur depuis le JWT
|
||||
const userId = req.user?.id || 'system';
|
||||
|
||||
await this.configService.markSetupCompleted(userId);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Configuration initiale terminée avec succès',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Erreur lors de la finalisation de la configuration',
|
||||
error: error.message,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test de la connexion SMTP
|
||||
* POST /api/v1/configuration/test-smtp
|
||||
*/
|
||||
@Post('test-smtp')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin')
|
||||
async testSmtp(@Body() testSmtpDto: TestSmtpDto) {
|
||||
try {
|
||||
const result = await this.configService.testSmtpConnection(testSmtpDto.testEmail);
|
||||
|
||||
if (result.success) {
|
||||
return {
|
||||
success: true,
|
||||
message: 'Connexion SMTP réussie. Email de test envoyé.',
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Échec du test SMTP',
|
||||
error: result.error,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Erreur lors du test SMTP',
|
||||
error: error.message,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mise à jour multiple des configurations
|
||||
* PATCH /api/v1/configuration/bulk
|
||||
*/
|
||||
@Patch('bulk')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin')
|
||||
async updateBulk(@Body() updateConfigDto: UpdateConfigDto, @Request() req: any) {
|
||||
try {
|
||||
// TODO: Récupérer l'ID utilisateur depuis le JWT
|
||||
const userId = req.user?.id || null;
|
||||
|
||||
let updated = 0;
|
||||
const errors: string[] = [];
|
||||
|
||||
// Parcourir toutes les clés du DTO
|
||||
for (const [key, value] of Object.entries(updateConfigDto)) {
|
||||
if (value !== undefined) {
|
||||
try {
|
||||
await this.configService.set(key, value, userId);
|
||||
updated++;
|
||||
} catch (error) {
|
||||
errors.push(`${key}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recharger le cache après les modifications
|
||||
await this.configService.loadCache();
|
||||
|
||||
if (errors.length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Certaines configurations n\'ont pas pu être mises à jour',
|
||||
updated,
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Configuration mise à jour avec succès',
|
||||
updated,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Erreur lors de la mise à jour des configurations',
|
||||
error: error.message,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupérer toutes les configurations (pour l'admin)
|
||||
* GET /api/v1/configuration
|
||||
*/
|
||||
@Get()
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin')
|
||||
async getAll() {
|
||||
try {
|
||||
const configs = await this.configService.getAll();
|
||||
return {
|
||||
success: true,
|
||||
data: configs,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Erreur lors de la récupération des configurations',
|
||||
error: error.message,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupérer les configurations par catégorie
|
||||
* GET /api/v1/configuration/:category
|
||||
*/
|
||||
@Get(':category')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin')
|
||||
async getByCategory(@Param('category') category: string) {
|
||||
try {
|
||||
if (!['email', 'app', 'security'].includes(category)) {
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Catégorie invalide. Valeurs acceptées: email, app, security',
|
||||
},
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
|
||||
const configs = await this.configService.getByCategory(category);
|
||||
return {
|
||||
success: true,
|
||||
data: configs,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) {
|
||||
throw error;
|
||||
}
|
||||
throw new HttpException(
|
||||
{
|
||||
success: false,
|
||||
message: 'Erreur lors de la récupération des configurations',
|
||||
error: error.message,
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Configuration } from '../../entities/configuration.entity';
|
||||
import { AppConfigService } from './config.service';
|
||||
import { ConfigController } from './config.controller';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Configuration])],
|
||||
controllers: [ConfigController],
|
||||
providers: [AppConfigService],
|
||||
exports: [AppConfigService],
|
||||
})
|
||||
export class AppConfigModule {}
|
||||
|
||||
@ -1,338 +0,0 @@
|
||||
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Configuration } from '../../entities/configuration.entity';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
@Injectable()
|
||||
export class AppConfigService implements OnModuleInit {
|
||||
private readonly logger = new Logger(AppConfigService.name);
|
||||
private cache: Map<string, any> = new Map();
|
||||
private readonly ENCRYPTION_KEY: string;
|
||||
private readonly ENCRYPTION_ALGORITHM = 'aes-256-cbc';
|
||||
private readonly IV_LENGTH = 16;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Configuration)
|
||||
private configRepo: Repository<Configuration>,
|
||||
) {
|
||||
// Clé de chiffrement depuis les variables d'environnement
|
||||
// En production, cette clé doit être générée de manière sécurisée
|
||||
this.ENCRYPTION_KEY =
|
||||
process.env.CONFIG_ENCRYPTION_KEY ||
|
||||
crypto.randomBytes(32).toString('hex');
|
||||
|
||||
if (!process.env.CONFIG_ENCRYPTION_KEY) {
|
||||
this.logger.warn(
|
||||
'⚠️ CONFIG_ENCRYPTION_KEY non définie. Utilisation d\'une clé temporaire (NON RECOMMANDÉ EN PRODUCTION)',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chargement du cache au démarrage de l'application
|
||||
*/
|
||||
async onModuleInit() {
|
||||
await this.loadCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Chargement de toutes les configurations en cache
|
||||
*/
|
||||
async loadCache(): Promise<void> {
|
||||
try {
|
||||
const configs = await this.configRepo.find();
|
||||
this.logger.log(`📦 Chargement de ${configs.length} configurations en cache`);
|
||||
|
||||
for (const config of configs) {
|
||||
let value = config.valeur;
|
||||
|
||||
// Déchiffrement si nécessaire
|
||||
if (config.type === 'encrypted' && value) {
|
||||
try {
|
||||
value = this.decrypt(value);
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`❌ Erreur de déchiffrement pour la clé '${config.cle}'`,
|
||||
error,
|
||||
);
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion de type
|
||||
const convertedValue = this.convertType(value, config.type);
|
||||
this.cache.set(config.cle, convertedValue);
|
||||
}
|
||||
|
||||
this.logger.log('✅ Cache de configuration chargé avec succès');
|
||||
} catch (error) {
|
||||
this.logger.error('❌ Erreur lors du chargement du cache', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupération d'une valeur de configuration
|
||||
* @param key Clé de configuration
|
||||
* @param defaultValue Valeur par défaut si la clé n'existe pas
|
||||
* @returns Valeur de configuration
|
||||
*/
|
||||
get<T = any>(key: string, defaultValue?: T): T {
|
||||
if (this.cache.has(key)) {
|
||||
return this.cache.get(key) as T;
|
||||
}
|
||||
|
||||
if (defaultValue !== undefined) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
this.logger.warn(`⚠️ Configuration '${key}' non trouvée et aucune valeur par défaut fournie`);
|
||||
return undefined as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mise à jour d'une valeur de configuration
|
||||
* @param key Clé de configuration
|
||||
* @param value Nouvelle valeur
|
||||
* @param userId ID de l'utilisateur qui modifie
|
||||
*/
|
||||
async set(key: string, value: any, userId?: string): Promise<void> {
|
||||
const config = await this.configRepo.findOne({ where: { cle: key } });
|
||||
|
||||
if (!config) {
|
||||
throw new Error(`Configuration '${key}' non trouvée`);
|
||||
}
|
||||
|
||||
let valueToStore = value !== null && value !== undefined ? String(value) : null;
|
||||
|
||||
// Chiffrement si nécessaire
|
||||
if (config.type === 'encrypted' && valueToStore) {
|
||||
valueToStore = this.encrypt(valueToStore);
|
||||
}
|
||||
|
||||
config.valeur = valueToStore;
|
||||
config.modifieLe = new Date();
|
||||
|
||||
if (userId) {
|
||||
config.modifiePar = { id: userId } as any;
|
||||
}
|
||||
|
||||
await this.configRepo.save(config);
|
||||
|
||||
// Mise à jour du cache (avec la valeur déchiffrée)
|
||||
this.cache.set(key, value);
|
||||
|
||||
this.logger.log(`✅ Configuration '${key}' mise à jour`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupération de toutes les configurations par catégorie
|
||||
* @param category Catégorie de configuration
|
||||
* @returns Objet clé/valeur des configurations
|
||||
*/
|
||||
async getByCategory(category: string): Promise<Record<string, any>> {
|
||||
const configs = await this.configRepo.find({
|
||||
where: { categorie: category as any },
|
||||
});
|
||||
|
||||
const result: Record<string, any> = {};
|
||||
|
||||
for (const config of configs) {
|
||||
let value = config.valeur;
|
||||
|
||||
// Masquer les mots de passe
|
||||
if (config.type === 'encrypted') {
|
||||
value = value ? '***********' : null;
|
||||
} else {
|
||||
value = this.convertType(value, config.type);
|
||||
}
|
||||
|
||||
result[config.cle] = {
|
||||
value,
|
||||
type: config.type,
|
||||
description: config.description,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupération de toutes les configurations (pour l'admin)
|
||||
* @returns Liste de toutes les configurations
|
||||
*/
|
||||
async getAll(): Promise<Configuration[]> {
|
||||
const configs = await this.configRepo.find({
|
||||
order: { categorie: 'ASC', cle: 'ASC' },
|
||||
});
|
||||
|
||||
// Masquer les valeurs chiffrées
|
||||
return configs.map((config) => ({
|
||||
...config,
|
||||
valeur: config.type === 'encrypted' && config.valeur ? '***********' : config.valeur,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test de la configuration SMTP
|
||||
* @param testEmail Email de destination pour le test
|
||||
* @returns Objet avec success et error éventuel
|
||||
*/
|
||||
async testSmtpConnection(testEmail?: string): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
this.logger.log('🧪 Test de connexion SMTP...');
|
||||
|
||||
// Récupération de la configuration SMTP
|
||||
const smtpHost = this.get<string>('smtp_host');
|
||||
const smtpPort = this.get<number>('smtp_port');
|
||||
const smtpSecure = this.get<boolean>('smtp_secure');
|
||||
const smtpAuthRequired = this.get<boolean>('smtp_auth_required');
|
||||
const smtpUser = this.get<string>('smtp_user');
|
||||
const smtpPassword = this.get<string>('smtp_password');
|
||||
const emailFromName = this.get<string>('email_from_name');
|
||||
const emailFromAddress = this.get<string>('email_from_address');
|
||||
|
||||
// Import dynamique de nodemailer
|
||||
const nodemailer = await import('nodemailer');
|
||||
|
||||
// Configuration du transporteur
|
||||
const transportConfig: any = {
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: smtpSecure,
|
||||
};
|
||||
|
||||
if (smtpAuthRequired && smtpUser && smtpPassword) {
|
||||
transportConfig.auth = {
|
||||
user: smtpUser,
|
||||
pass: smtpPassword,
|
||||
};
|
||||
}
|
||||
|
||||
const transporter = nodemailer.createTransport(transportConfig);
|
||||
|
||||
// Vérification de la connexion
|
||||
await transporter.verify();
|
||||
this.logger.log('✅ Connexion SMTP vérifiée');
|
||||
|
||||
// Si un email de test est fourni, on envoie un email
|
||||
if (testEmail) {
|
||||
await transporter.sendMail({
|
||||
from: `"${emailFromName}" <${emailFromAddress}>`,
|
||||
to: testEmail,
|
||||
subject: '🧪 Test de configuration SMTP - P\'titsPas',
|
||||
text: 'Ceci est un email de test pour vérifier la configuration SMTP de votre application P\'titsPas.',
|
||||
html: `
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
|
||||
<h2 style="color: #4CAF50;">✅ Test de configuration SMTP réussi !</h2>
|
||||
<p>Ceci est un email de test pour vérifier la configuration SMTP de votre application <strong>P'titsPas</strong>.</p>
|
||||
<p>Si vous recevez cet email, cela signifie que votre configuration SMTP fonctionne correctement.</p>
|
||||
<hr style="border: 1px solid #eee; margin: 20px 0;">
|
||||
<p style="color: #666; font-size: 12px;">
|
||||
Cet email a été envoyé automatiquement depuis votre application P'titsPas.<br>
|
||||
Configuration testée le ${new Date().toLocaleString('fr-FR')}
|
||||
</p>
|
||||
</div>
|
||||
`,
|
||||
});
|
||||
this.logger.log(`📧 Email de test envoyé à ${testEmail}`);
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
this.logger.error('❌ Échec du test SMTP', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message || 'Erreur inconnue lors du test SMTP',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérification si la configuration initiale est terminée
|
||||
* @returns true si la configuration est terminée
|
||||
*/
|
||||
isSetupCompleted(): boolean {
|
||||
return this.get<boolean>('setup_completed', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marquer la configuration initiale comme terminée
|
||||
* @param userId ID de l'utilisateur qui termine la configuration
|
||||
*/
|
||||
async markSetupCompleted(userId: string): Promise<void> {
|
||||
await this.set('setup_completed', 'true', userId);
|
||||
this.logger.log('✅ Configuration initiale marquée comme terminée');
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversion de type selon le type de configuration
|
||||
* @param value Valeur à convertir
|
||||
* @param type Type cible
|
||||
* @returns Valeur convertie
|
||||
*/
|
||||
private convertType(value: string | null, type: string): any {
|
||||
if (value === null || value === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'number':
|
||||
return parseFloat(value);
|
||||
case 'boolean':
|
||||
return value === 'true' || value === '1';
|
||||
case 'json':
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
case 'string':
|
||||
case 'encrypted':
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chiffrement AES-256-CBC
|
||||
* @param text Texte à chiffrer
|
||||
* @returns Texte chiffré (format: iv:encrypted)
|
||||
*/
|
||||
private encrypt(text: string): string {
|
||||
const iv = crypto.randomBytes(this.IV_LENGTH);
|
||||
const key = Buffer.from(this.ENCRYPTION_KEY, 'hex');
|
||||
const cipher = crypto.createCipheriv(this.ENCRYPTION_ALGORITHM, key, iv);
|
||||
|
||||
let encrypted = cipher.update(text, 'utf8', 'hex');
|
||||
encrypted += cipher.final('hex');
|
||||
|
||||
// Format: iv:encrypted
|
||||
return `${iv.toString('hex')}:${encrypted}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Déchiffrement AES-256-CBC
|
||||
* @param encryptedText Texte chiffré (format: iv:encrypted)
|
||||
* @returns Texte déchiffré
|
||||
*/
|
||||
private decrypt(encryptedText: string): string {
|
||||
const parts = encryptedText.split(':');
|
||||
if (parts.length !== 2) {
|
||||
throw new Error('Format de chiffrement invalide');
|
||||
}
|
||||
|
||||
const iv = Buffer.from(parts[0], 'hex');
|
||||
const encrypted = parts[1];
|
||||
const key = Buffer.from(this.ENCRYPTION_KEY, 'hex');
|
||||
|
||||
const decipher = crypto.createDecipheriv(this.ENCRYPTION_ALGORITHM, key, iv);
|
||||
|
||||
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
|
||||
return decrypted;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
import { IsEmail } from 'class-validator';
|
||||
|
||||
export class TestSmtpDto {
|
||||
@IsEmail()
|
||||
testEmail: string;
|
||||
}
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
import { IsString, IsOptional, IsNumber, IsBoolean, IsEmail, IsUrl } from 'class-validator';
|
||||
|
||||
export class UpdateConfigDto {
|
||||
// Configuration Email (SMTP)
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
smtp_host?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
smtp_port?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
smtp_secure?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
smtp_auth_required?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
smtp_user?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
smtp_password?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
email_from_name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email_from_address?: string;
|
||||
|
||||
// Configuration Application
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
app_name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsUrl()
|
||||
app_url?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
app_logo_url?: string;
|
||||
|
||||
// Configuration Sécurité
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
password_reset_token_expiry_days?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
jwt_expiry_hours?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
max_upload_size_mb?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
bcrypt_rounds?: number;
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
export * from './config.module';
|
||||
export * from './config.service';
|
||||
|
||||
@ -1,202 +0,0 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Patch,
|
||||
Param,
|
||||
Body,
|
||||
UseInterceptors,
|
||||
UploadedFile,
|
||||
Res,
|
||||
HttpStatus,
|
||||
BadRequestException,
|
||||
ParseUUIDPipe,
|
||||
StreamableFile,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import type { Response } from 'express';
|
||||
import { DocumentsLegauxService } from './documents-legaux.service';
|
||||
import { UploadDocumentDto } from './dto/upload-document.dto';
|
||||
import { DocumentsActifsResponseDto } from './dto/documents-actifs.dto';
|
||||
import { DocumentVersionDto } from './dto/document-version.dto';
|
||||
|
||||
@Controller('documents-legaux')
|
||||
export class DocumentsLegauxController {
|
||||
constructor(private readonly documentsService: DocumentsLegauxService) {}
|
||||
|
||||
/**
|
||||
* GET /api/v1/documents-legaux/actifs
|
||||
* Récupérer les documents actifs (CGU + Privacy)
|
||||
* PUBLIC
|
||||
*/
|
||||
@Get('actifs')
|
||||
async getDocumentsActifs(): Promise<DocumentsActifsResponseDto> {
|
||||
const { cgu, privacy } = await this.documentsService.getDocumentsActifs();
|
||||
|
||||
return {
|
||||
cgu: {
|
||||
id: cgu.id,
|
||||
type: cgu.type,
|
||||
version: cgu.version,
|
||||
url: `/api/v1/documents-legaux/${cgu.id}/download`,
|
||||
activeLe: cgu.activeLe,
|
||||
},
|
||||
privacy: {
|
||||
id: privacy.id,
|
||||
type: privacy.type,
|
||||
version: privacy.version,
|
||||
url: `/api/v1/documents-legaux/${privacy.id}/download`,
|
||||
activeLe: privacy.activeLe,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/documents-legaux/:type/versions
|
||||
* Lister toutes les versions d'un type de document
|
||||
* ADMIN ONLY
|
||||
*/
|
||||
@Get(':type/versions')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin', 'administrateur')
|
||||
async listerVersions(@Param('type') type: string): Promise<DocumentVersionDto[]> {
|
||||
if (type !== 'cgu' && type !== 'privacy') {
|
||||
throw new BadRequestException('Le type doit être "cgu" ou "privacy"');
|
||||
}
|
||||
|
||||
const documents = await this.documentsService.listerVersions(type as 'cgu' | 'privacy');
|
||||
|
||||
return documents.map((doc) => ({
|
||||
id: doc.id,
|
||||
version: doc.version,
|
||||
fichier_nom: doc.fichier_nom,
|
||||
actif: doc.actif,
|
||||
televersePar: doc.televersePar
|
||||
? {
|
||||
id: doc.televersePar.id,
|
||||
prenom: doc.televersePar.prenom,
|
||||
nom: doc.televersePar.nom,
|
||||
}
|
||||
: null,
|
||||
televerseLe: doc.televerseLe,
|
||||
activeLe: doc.activeLe,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/v1/documents-legaux
|
||||
* Upload une nouvelle version d'un document
|
||||
* ADMIN ONLY
|
||||
*/
|
||||
@Post()
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin', 'administrateur')
|
||||
async uploadDocument(
|
||||
@Body() uploadDto: UploadDocumentDto,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
// @CurrentUser() user: any, // TODO: Décommenter quand le guard sera implémenté
|
||||
) {
|
||||
if (!file) {
|
||||
throw new BadRequestException('Aucun fichier fourni');
|
||||
}
|
||||
|
||||
// TODO: Récupérer l'ID utilisateur depuis le guard
|
||||
const userId = '00000000-0000-0000-0000-000000000000'; // Temporaire
|
||||
|
||||
const document = await this.documentsService.uploadNouvelleVersion(
|
||||
uploadDto.type,
|
||||
file,
|
||||
userId,
|
||||
);
|
||||
|
||||
return {
|
||||
id: document.id,
|
||||
type: document.type,
|
||||
version: document.version,
|
||||
fichier_nom: document.fichier_nom,
|
||||
actif: document.actif,
|
||||
televerseLe: document.televerseLe,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH /api/v1/documents-legaux/:id/activer
|
||||
* Activer une version d'un document
|
||||
* ADMIN ONLY
|
||||
*/
|
||||
@Patch(':id/activer')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin', 'administrateur')
|
||||
async activerVersion(@Param('id', ParseUUIDPipe) documentId: string) {
|
||||
await this.documentsService.activerVersion(documentId);
|
||||
|
||||
// Récupérer le document pour retourner les infos
|
||||
const documents = await this.documentsService.listerVersions('cgu');
|
||||
const document = documents.find((d) => d.id === documentId);
|
||||
|
||||
if (!document) {
|
||||
const documentsPrivacy = await this.documentsService.listerVersions('privacy');
|
||||
const docPrivacy = documentsPrivacy.find((d) => d.id === documentId);
|
||||
|
||||
if (!docPrivacy) {
|
||||
throw new BadRequestException('Document non trouvé');
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Document activé avec succès',
|
||||
documentId: docPrivacy.id,
|
||||
type: docPrivacy.type,
|
||||
version: docPrivacy.version,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Document activé avec succès',
|
||||
documentId: document.id,
|
||||
type: document.type,
|
||||
version: document.version,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/documents-legaux/:id/download
|
||||
* Télécharger un document
|
||||
* PUBLIC
|
||||
*/
|
||||
@Get(':id/download')
|
||||
async telechargerDocument(
|
||||
@Param('id', ParseUUIDPipe) documentId: string,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
const { stream, filename } = await this.documentsService.telechargerDocument(documentId);
|
||||
|
||||
res.set({
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `attachment; filename="${filename}"`,
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).send(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/documents-legaux/:id/verifier-integrite
|
||||
* Vérifier l'intégrité d'un document (hash SHA-256)
|
||||
* ADMIN ONLY
|
||||
*/
|
||||
@Get(':id/verifier-integrite')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
// @Roles('super_admin', 'administrateur')
|
||||
async verifierIntegrite(@Param('id', ParseUUIDPipe) documentId: string) {
|
||||
const integre = await this.documentsService.verifierIntegrite(documentId);
|
||||
|
||||
return {
|
||||
documentId,
|
||||
integre,
|
||||
message: integre
|
||||
? 'Le document est intègre (hash valide)'
|
||||
: 'ALERTE : Le document a été modifié (hash invalide)',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { DocumentLegal } from '../../entities/document-legal.entity';
|
||||
import { AcceptationDocument } from '../../entities/acceptation-document.entity';
|
||||
import { DocumentsLegauxService } from './documents-legaux.service';
|
||||
import { DocumentsLegauxController } from './documents-legaux.controller';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([DocumentLegal, AcceptationDocument])],
|
||||
providers: [DocumentsLegauxService],
|
||||
controllers: [DocumentsLegauxController],
|
||||
exports: [DocumentsLegauxService],
|
||||
})
|
||||
export class DocumentsLegauxModule {}
|
||||
|
||||