Compare commits
No commits in common. "master" and "archive/maquette-initiale" have entirely different histories.
master
...
archive/ma
18
.gitattributes
vendored
@ -1,18 +0,0 @@
|
|||||||
# Fins de ligne : toujours LF dans le dépôt (évite les conflits Linux/Windows)
|
|
||||||
* text=auto eol=lf
|
|
||||||
|
|
||||||
# Fichiers binaires : pas de conversion
|
|
||||||
*.png binary
|
|
||||||
*.jpg binary
|
|
||||||
*.jpeg binary
|
|
||||||
*.gif binary
|
|
||||||
*.ico binary
|
|
||||||
*.webp binary
|
|
||||||
*.pdf binary
|
|
||||||
*.woff binary
|
|
||||||
*.woff2 binary
|
|
||||||
*.ttf binary
|
|
||||||
*.eot binary
|
|
||||||
|
|
||||||
# Scripts shell : toujours LF
|
|
||||||
*.sh text eol=lf
|
|
||||||
5
.gitignore
vendored
@ -37,10 +37,6 @@ yarn-error.log*
|
|||||||
.pub-cache/
|
.pub-cache/
|
||||||
.pub/
|
.pub/
|
||||||
/build/
|
/build/
|
||||||
**/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
|
|
||||||
**/windows/flutter/generated_plugin_registrant.cc
|
|
||||||
**/windows/flutter/generated_plugin_registrant.h
|
|
||||||
**/windows/flutter/generated_plugins.cmake
|
|
||||||
|
|
||||||
# Coverage
|
# Coverage
|
||||||
coverage/
|
coverage/
|
||||||
@ -56,4 +52,3 @@ Xcf/**
|
|||||||
# Release notes
|
# Release notes
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
Ressources/
|
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
@ -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,26 +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
|
|
||||||
|
|
||||||
# Log de chaque appel API (mode debug) — mettre à true pour tracer les requêtes front
|
|
||||||
# LOG_API_REQUESTS=true
|
|
||||||
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",
|
"name": "petitspas-backend",
|
||||||
"version": "0.0.1",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "Backend pour l'application P'titsPas",
|
||||||
"author": "",
|
"main": "dist/index.js",
|
||||||
"private": true,
|
|
||||||
"license": "UNLICENSED",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typeorm": "typeorm-ts-node-commonjs",
|
"start": "node dist/index.js",
|
||||||
"migration:run": "npm run typeorm migration:run",
|
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
||||||
"build": "nest build",
|
"build": "tsc",
|
||||||
"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",
|
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watch",
|
"init-admin": "ts-node src/scripts/initAdmin.ts"
|
||||||
"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"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.1.6",
|
"@nestjs/common": "^11.1.0",
|
||||||
"@nestjs/config": "^4.0.2",
|
"@prisma/client": "^6.7.0",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@types/jsonwebtoken": "^9.0.9",
|
||||||
"@nestjs/jwt": "^11.0.0",
|
"bcrypt": "^5.1.1",
|
||||||
"@nestjs/mapped-types": "^2.1.0",
|
"cors": "^2.8.5",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"express": "^4.18.2",
|
||||||
"@nestjs/swagger": "^11.2.0",
|
"helmet": "^7.1.0",
|
||||||
"@nestjs/typeorm": "^11.0.0",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"@sentry/nestjs": "^10.10.0",
|
"morgan": "^1.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"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@types/bcrypt": "^5.0.2",
|
||||||
"@eslint/js": "^9.18.0",
|
"@types/cors": "^2.8.17",
|
||||||
"@nestjs/cli": "^11.0.10",
|
"@types/express": "^4.17.21",
|
||||||
"@nestjs/schematics": "^11.0.0",
|
"@types/helmet": "^4.0.0",
|
||||||
"@nestjs/testing": "^11.0.1",
|
"@types/morgan": "^1.9.9",
|
||||||
"@types/bcrypt": "^6.0.0",
|
"@types/node": "^20.11.19",
|
||||||
"@types/express": "^5.0.0",
|
"prisma": "^6.7.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",
|
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsconfig-paths": "^4.2.0",
|
"ts-node-dev": "^2.0.0",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.3.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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,89 +0,0 @@
|
|||||||
/**
|
|
||||||
* Crée l'issue Gitea "[Frontend] Inscription Parent – Branchement soumission formulaire à l'API"
|
|
||||||
* Usage: node backend/scripts/create-gitea-issue-parent-api.js
|
|
||||||
* Token : .gitea-token (racine du dépôt), sinon GITEA_TOKEN, sinon docs/BRIEFING-FRONTEND.md (voir PROCEDURE-API-GITEA.md)
|
|
||||||
*/
|
|
||||||
const https = require('https');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const repoRoot = path.join(__dirname, '../..');
|
|
||||||
let token = process.env.GITEA_TOKEN;
|
|
||||||
if (!token) {
|
|
||||||
try {
|
|
||||||
const tokenFile = path.join(repoRoot, '.gitea-token');
|
|
||||||
if (fs.existsSync(tokenFile)) {
|
|
||||||
token = fs.readFileSync(tokenFile, 'utf8').trim();
|
|
||||||
}
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
if (!token) {
|
|
||||||
try {
|
|
||||||
const briefing = fs.readFileSync(path.join(repoRoot, 'docs/BRIEFING-FRONTEND.md'), 'utf8');
|
|
||||||
const m = briefing.match(/Token:\s*(giteabu_[a-f0-9]+)/);
|
|
||||||
if (m) token = m[1].trim();
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
if (!token) {
|
|
||||||
console.error('Token non trouvé : créer .gitea-token à la racine ou export GITEA_TOKEN (voir docs/PROCEDURE-API-GITEA.md)');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = `## Description
|
|
||||||
|
|
||||||
Branchement du formulaire d'inscription parent (étape 5, récapitulatif) à l'endpoint d'inscription. Aujourd'hui la soumission n'appelle pas l'API : elle affiche uniquement une modale puis redirige vers le login.
|
|
||||||
|
|
||||||
**Estimation** : 4h | **Labels** : frontend, p3, auth, cdc
|
|
||||||
|
|
||||||
## Tâches
|
|
||||||
|
|
||||||
- [ ] Créer un service ou méthode (ex. AuthService.registerParent) appelant POST /api/v1/auth/register/parent
|
|
||||||
- [ ] Construire le body (DTO) à partir de UserRegistrationData (parent1, parent2, children, motivationText, CGU) en cohérence avec le backend (#18)
|
|
||||||
- [ ] Dans ParentRegisterStep5Screen, au clic « Soumettre » : appel API puis modale + redirection ou message d'erreur
|
|
||||||
- [ ] Gestion des photos enfants (base64 ou multipart selon API)
|
|
||||||
|
|
||||||
## Référence
|
|
||||||
|
|
||||||
20_WORKFLOW-CREATION-COMPTE.md § Étape 3 – Inscription d'un parent, backend #18`;
|
|
||||||
|
|
||||||
const payload = JSON.stringify({
|
|
||||||
title: "[Frontend] Inscription Parent – Branchement soumission formulaire à l'API",
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
|
|
||||||
const opts = {
|
|
||||||
hostname: 'git.ptits-pas.fr',
|
|
||||||
path: '/api/v1/repos/jmartin/petitspas/issues',
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
Authorization: 'token ' + token,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Content-Length': Buffer.byteLength(payload),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const req = https.request(opts, (res) => {
|
|
||||||
let d = '';
|
|
||||||
res.on('data', (c) => (d += c));
|
|
||||||
res.on('end', () => {
|
|
||||||
try {
|
|
||||||
const o = JSON.parse(d);
|
|
||||||
if (o.number) {
|
|
||||||
console.log('NUMBER:', o.number);
|
|
||||||
console.log('URL:', o.html_url);
|
|
||||||
} else {
|
|
||||||
console.error('Erreur API:', o.message || d);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Réponse:', d);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.on('error', (e) => {
|
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
req.write(payload);
|
|
||||||
req.end();
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
/**
|
|
||||||
* Liste toutes les issues Gitea (ouvertes + fermées) pour jmartin/petitspas.
|
|
||||||
* Token : .gitea-token (racine), GITEA_TOKEN, ou docs/BRIEFING-FRONTEND.md
|
|
||||||
*/
|
|
||||||
const https = require('https');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const repoRoot = path.join(__dirname, '../..');
|
|
||||||
let token = process.env.GITEA_TOKEN;
|
|
||||||
if (!token) {
|
|
||||||
try {
|
|
||||||
const tokenFile = path.join(repoRoot, '.gitea-token');
|
|
||||||
if (fs.existsSync(tokenFile)) token = fs.readFileSync(tokenFile, 'utf8').trim();
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
if (!token) {
|
|
||||||
try {
|
|
||||||
const briefing = fs.readFileSync(path.join(repoRoot, 'docs/BRIEFING-FRONTEND.md'), 'utf8');
|
|
||||||
const m = briefing.match(/Token:\s*(giteabu_[a-f0-9]+)/);
|
|
||||||
if (m) token = m[1].trim();
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
if (!token) {
|
|
||||||
console.error('Token non trouvé');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function get(path) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const opts = { hostname: 'git.ptits-pas.fr', path, method: 'GET', headers: { Authorization: 'token ' + token } };
|
|
||||||
const req = https.request(opts, (res) => {
|
|
||||||
let d = '';
|
|
||||||
res.on('data', (c) => (d += c));
|
|
||||||
res.on('end', () => {
|
|
||||||
try { resolve(JSON.parse(d)); } catch (e) { reject(e); }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.on('error', reject);
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const seen = new Map();
|
|
||||||
for (const state of ['open', 'closed']) {
|
|
||||||
for (let page = 1; ; page++) {
|
|
||||||
const raw = await get('/api/v1/repos/jmartin/petitspas/issues?state=' + state + '&limit=50&page=' + page + '&type=issues');
|
|
||||||
if (raw && raw.message && !Array.isArray(raw)) {
|
|
||||||
console.error('API:', raw.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
const list = Array.isArray(raw) ? raw : [];
|
|
||||||
for (const i of list) {
|
|
||||||
if (!i.pull_request) seen.set(i.number, { number: i.number, title: i.title, state: i.state });
|
|
||||||
}
|
|
||||||
if (list.length < 50) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const all = [...seen.values()].sort((a, b) => a.number - b.number);
|
|
||||||
console.log(JSON.stringify(all, null, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((e) => { console.error(e); process.exit(1); });
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Test POST /auth/register/am (ticket #90)
|
|
||||||
# Usage: ./scripts/test-register-am.sh [BASE_URL]
|
|
||||||
# Exemple: ./scripts/test-register-am.sh https://app.ptits-pas.fr/api/v1
|
|
||||||
# ./scripts/test-register-am.sh http://localhost:3000/api/v1
|
|
||||||
|
|
||||||
BASE_URL="${1:-http://localhost:3000/api/v1}"
|
|
||||||
echo "Testing POST $BASE_URL/auth/register/am"
|
|
||||||
echo "---"
|
|
||||||
|
|
||||||
curl -s -w "\n\nHTTP %{http_code}\n" -X POST "$BASE_URL/auth/register/am" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"email": "marie.dupont.test@ptits-pas.fr",
|
|
||||||
"prenom": "Marie",
|
|
||||||
"nom": "DUPONT",
|
|
||||||
"telephone": "0612345678",
|
|
||||||
"adresse": "1 rue Test",
|
|
||||||
"code_postal": "75001",
|
|
||||||
"ville": "Paris",
|
|
||||||
"consentement_photo": true,
|
|
||||||
"nir": "123456789012345",
|
|
||||||
"numero_agrement": "AGR-2024-001",
|
|
||||||
"capacite_accueil": 4,
|
|
||||||
"acceptation_cgu": true,
|
|
||||||
"acceptation_privacy": true
|
|
||||||
}'
|
|
||||||
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,73 +1,17 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { AppController } from './app.controller';
|
import { PrismaModule } from './prisma/prisma.module';
|
||||||
import { AppService } from './app.service';
|
import { AuthModule } from './auth/auth.module';
|
||||||
import appConfig from './config/app.config';
|
import { AdminModule } from './admin/admin.module';
|
||||||
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 { RelaisModule } from './routes/relais/relais.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
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,
|
isGlobal: true,
|
||||||
validationSchema: configValidationSchema,
|
|
||||||
}),
|
}),
|
||||||
TypeOrmModule.forRootAsync({
|
PrismaModule,
|
||||||
imports: [ConfigModule,
|
|
||||||
],
|
|
||||||
inject: [ConfigService],
|
|
||||||
useFactory: (config: ConfigService) => ({
|
|
||||||
type: 'postgres',
|
|
||||||
host: config.get('database.host'),
|
|
||||||
port: config.get<number>('database.port'),
|
|
||||||
username: config.get('database.username'),
|
|
||||||
password: config.get('database.password'),
|
|
||||||
database: config.get('database.database'),
|
|
||||||
entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
|
||||||
synchronize: false,
|
|
||||||
migrations: [__dirname + '/migrations/**/*{.ts,.js}'],
|
|
||||||
logging: true,
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
UserModule,
|
|
||||||
ParentsModule,
|
|
||||||
EnfantsModule,
|
|
||||||
AuthModule,
|
AuthModule,
|
||||||
AppConfigModule,
|
AdminModule,
|
||||||
DocumentsLegauxModule,
|
|
||||||
RelaisModule,
|
|
||||||
],
|
|
||||||
controllers: [AppController],
|
|
||||||
providers: [
|
|
||||||
AppService,
|
|
||||||
{
|
|
||||||
provide: APP_FILTER,
|
|
||||||
useClass: SentryGlobalFilter
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provide: APP_FILTER,
|
|
||||||
useClass: AllExceptionsFilter,
|
|
||||||
}
|
|
||||||
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
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,69 +0,0 @@
|
|||||||
import {
|
|
||||||
CallHandler,
|
|
||||||
ExecutionContext,
|
|
||||||
Injectable,
|
|
||||||
NestInterceptor,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { tap } from 'rxjs/operators';
|
|
||||||
import { Request } from 'express';
|
|
||||||
|
|
||||||
/** Clés à masquer dans les logs (corps de requête) */
|
|
||||||
const SENSITIVE_KEYS = [
|
|
||||||
'password',
|
|
||||||
'smtp_password',
|
|
||||||
'token',
|
|
||||||
'accessToken',
|
|
||||||
'refreshToken',
|
|
||||||
'secret',
|
|
||||||
];
|
|
||||||
|
|
||||||
function maskBody(body: unknown): unknown {
|
|
||||||
if (body === null || body === undefined) return body;
|
|
||||||
if (typeof body !== 'object') return body;
|
|
||||||
const out: Record<string, unknown> = {};
|
|
||||||
for (const [key, value] of Object.entries(body)) {
|
|
||||||
const lower = key.toLowerCase();
|
|
||||||
const isSensitive = SENSITIVE_KEYS.some((s) => lower.includes(s));
|
|
||||||
out[key] = isSensitive ? '***' : value;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class LogRequestInterceptor implements NestInterceptor {
|
|
||||||
private readonly enabled: boolean;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.enabled =
|
|
||||||
process.env.LOG_API_REQUESTS === 'true' ||
|
|
||||||
process.env.LOG_API_REQUESTS === '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
|
||||||
if (!this.enabled) return next.handle();
|
|
||||||
|
|
||||||
const http = context.switchToHttp();
|
|
||||||
const req = http.getRequest<Request>();
|
|
||||||
const { method, url, body, query } = req;
|
|
||||||
const hasBody = body && Object.keys(body).length > 0;
|
|
||||||
|
|
||||||
const logLine = [
|
|
||||||
`[API] ${method} ${url}`,
|
|
||||||
Object.keys(query || {}).length ? `query=${JSON.stringify(query)}` : '',
|
|
||||||
hasBody ? `body=${JSON.stringify(maskBody(body))}` : '',
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
console.log(logLine);
|
|
||||||
|
|
||||||
return next.handle().pipe(
|
|
||||||
tap({
|
|
||||||
next: () => {
|
|
||||||
// Optionnel: log du statut en fin de requête (si besoin plus tard)
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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,109 +0,0 @@
|
|||||||
/**
|
|
||||||
* Utilitaire de validation du NIR (numéro de sécurité sociale français).
|
|
||||||
* - Format 15 caractères (chiffres ou 2A/2B pour la Corse).
|
|
||||||
* - Clé de contrôle : 97 - (NIR13 mod 97). Pour 2A/2B, conversion temporaire (INSEE : 2A→19, 2B→20).
|
|
||||||
* - En cas d'incohérence avec les données (sexe, date, lieu) : warning uniquement, pas de rejet.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const NIR_CORSE_2A = '19';
|
|
||||||
const NIR_CORSE_2B = '20';
|
|
||||||
|
|
||||||
/** Regex 15 caractères : sexe (1-3) + 4 chiffres + (2A|2B|2 chiffres) + 6 chiffres + 2 chiffres clé */
|
|
||||||
const NIR_FORMAT = /^[1-3]\d{4}(?:2A|2B|\d{2})\d{6}\d{2}$/i;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convertit le NIR en chaîne de 13 chiffres pour le calcul de la clé (2A→19, 2B→20).
|
|
||||||
*/
|
|
||||||
export function nirTo13Digits(nir: string): string {
|
|
||||||
const n = nir.toUpperCase().replace(/\s/g, '');
|
|
||||||
if (n.length !== 15) return '';
|
|
||||||
const dept = n.slice(5, 7);
|
|
||||||
let deptNum: string;
|
|
||||||
if (dept === '2A') deptNum = NIR_CORSE_2A;
|
|
||||||
else if (dept === '2B') deptNum = NIR_CORSE_2B;
|
|
||||||
else deptNum = dept;
|
|
||||||
return n.slice(0, 5) + deptNum + n.slice(7, 13);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vérifie que le format NIR est valide (15 caractères, 2A/2B acceptés).
|
|
||||||
*/
|
|
||||||
export function isNirFormatValid(nir: string): boolean {
|
|
||||||
if (!nir || typeof nir !== 'string') return false;
|
|
||||||
const n = nir.replace(/\s/g, '').toUpperCase();
|
|
||||||
return NIR_FORMAT.test(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calcule la clé de contrôle attendue (97 - (NIR13 mod 97)).
|
|
||||||
* Retourne un nombre entre 1 et 97.
|
|
||||||
*/
|
|
||||||
export function computeNirKey(nir13: string): number {
|
|
||||||
const num = parseInt(nir13, 10);
|
|
||||||
if (Number.isNaN(num) || nir13.length !== 13) return -1;
|
|
||||||
return 97 - (num % 97);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vérifie la clé de contrôle du NIR (15 caractères).
|
|
||||||
* Retourne true si le NIR est valide (format + clé).
|
|
||||||
*/
|
|
||||||
export function isNirKeyValid(nir: string): boolean {
|
|
||||||
const n = nir.replace(/\s/g, '').toUpperCase();
|
|
||||||
if (n.length !== 15) return false;
|
|
||||||
const nir13 = nirTo13Digits(n);
|
|
||||||
if (nir13.length !== 13) return false;
|
|
||||||
const expectedKey = computeNirKey(nir13);
|
|
||||||
const actualKey = parseInt(n.slice(13, 15), 10);
|
|
||||||
return expectedKey === actualKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NirValidationResult {
|
|
||||||
valid: boolean;
|
|
||||||
error?: string;
|
|
||||||
warning?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Valide le NIR (format + clé). En cas d'incohérence avec date de naissance ou sexe, ajoute un warning sans invalider.
|
|
||||||
*/
|
|
||||||
export function validateNir(
|
|
||||||
nir: string,
|
|
||||||
options?: { dateNaissance?: string; genre?: 'H' | 'F' },
|
|
||||||
): NirValidationResult {
|
|
||||||
const n = (nir || '').replace(/\s/g, '').toUpperCase();
|
|
||||||
if (n.length === 0) return { valid: false, error: 'Le NIR est requis' };
|
|
||||||
if (!isNirFormatValid(n)) {
|
|
||||||
return { valid: false, error: 'Le NIR doit contenir 15 caractères (chiffres, ou 2A/2B pour la Corse)' };
|
|
||||||
}
|
|
||||||
if (!isNirKeyValid(n)) {
|
|
||||||
return { valid: false, error: 'Clé de contrôle du NIR invalide' };
|
|
||||||
}
|
|
||||||
let warning: string | undefined;
|
|
||||||
if (options?.genre) {
|
|
||||||
const sexNir = n[0];
|
|
||||||
const expectedSex = options.genre === 'F' ? '2' : '1';
|
|
||||||
if (sexNir !== expectedSex) {
|
|
||||||
warning = 'Le NIR ne correspond pas au genre indiqué (position 1 du NIR).';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (options?.dateNaissance) {
|
|
||||||
try {
|
|
||||||
const d = new Date(options.dateNaissance);
|
|
||||||
if (!Number.isNaN(d.getTime())) {
|
|
||||||
const year2 = d.getFullYear() % 100;
|
|
||||||
const month = d.getMonth() + 1;
|
|
||||||
const nirYear = parseInt(n.slice(1, 3), 10);
|
|
||||||
const nirMonth = parseInt(n.slice(3, 5), 10);
|
|
||||||
if (nirYear !== year2 || nirMonth !== month) {
|
|
||||||
warning = warning
|
|
||||||
? `${warning} Le NIR ne correspond pas à la date de naissance (positions 2-5).`
|
|
||||||
: 'Le NIR ne correspond pas à la date de naissance indiquée (positions 2-5).';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { valid: true, warning };
|
|
||||||
}
|
|
||||||
@ -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,15 +0,0 @@
|
|||||||
import { DataSource } from 'typeorm';
|
|
||||||
import { config } from 'dotenv';
|
|
||||||
|
|
||||||
config();
|
|
||||||
|
|
||||||
export default new DataSource({
|
|
||||||
type: 'postgres',
|
|
||||||
host: process.env.DATABASE_HOST,
|
|
||||||
port: parseInt(process.env.DATABASE_PORT || '5432', 10),
|
|
||||||
username: process.env.DATABASE_USERNAME,
|
|
||||||
password: process.env.DATABASE_PASSWORD,
|
|
||||||
database: process.env.DATABASE_NAME,
|
|
||||||
entities: ['src/**/*.entity.ts'],
|
|
||||||
migrations: ['src/migrations/*.ts'],
|
|
||||||
});
|
|
||||||
@ -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,54 +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;
|
|
||||||
|
|
||||||
/** Numéro de dossier (format AAAA-NNNNNN), même valeur que sur utilisateurs (ticket #103) */
|
|
||||||
@Column({ name: 'numero_dossier', length: 20, nullable: true })
|
|
||||||
numero_dossier?: string;
|
|
||||||
}
|
|
||||||
@ -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,35 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryColumn, Column, 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;
|
|
||||||
|
|
||||||
/** Numéro de dossier famille (format AAAA-NNNNNN), attribué à la soumission (ticket #103) */
|
|
||||||
@Column({ name: 'numero_dossier', length: 20, nullable: true })
|
|
||||||
numero_dossier?: string;
|
|
||||||
|
|
||||||
// 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,35 +0,0 @@
|
|||||||
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, OneToMany } from 'typeorm';
|
|
||||||
import { Users } from './users.entity';
|
|
||||||
|
|
||||||
@Entity('relais', { schema: 'public' })
|
|
||||||
export class Relais {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column({ name: 'nom' })
|
|
||||||
nom: string;
|
|
||||||
|
|
||||||
@Column({ name: 'adresse' })
|
|
||||||
adresse: string;
|
|
||||||
|
|
||||||
@Column({ type: 'jsonb', name: 'horaires_ouverture', nullable: true })
|
|
||||||
horaires_ouverture?: any;
|
|
||||||
|
|
||||||
@Column({ name: 'ligne_fixe', nullable: true })
|
|
||||||
ligne_fixe?: string;
|
|
||||||
|
|
||||||
@Column({ default: true, name: 'actif' })
|
|
||||||
actif: boolean;
|
|
||||||
|
|
||||||
@Column({ type: 'text', name: 'notes', nullable: true })
|
|
||||||
notes?: string;
|
|
||||||
|
|
||||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
|
||||||
cree_le: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
|
||||||
modifie_le: Date;
|
|
||||||
|
|
||||||
@OneToMany(() => Users, user => user.relais)
|
|
||||||
gestionnaires: Users[];
|
|
||||||
}
|
|
||||||
@ -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,170 +0,0 @@
|
|||||||
import {
|
|
||||||
Entity, PrimaryGeneratedColumn, Column,
|
|
||||||
CreateDateColumn, UpdateDateColumn,
|
|
||||||
OneToOne, OneToMany, ManyToOne, JoinColumn
|
|
||||||
} from 'typeorm';
|
|
||||||
import { AssistanteMaternelle } from './assistantes_maternelles.entity';
|
|
||||||
import { Parents } from './parents.entity';
|
|
||||||
import { Message } from './messages.entity';
|
|
||||||
import { Relais } from './relais.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',
|
|
||||||
REFUSE = 'refuse',
|
|
||||||
}
|
|
||||||
|
|
||||||
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.ACTIF,
|
|
||||||
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;
|
|
||||||
|
|
||||||
/** Token pour reprise après refus (lien email), ticket #110 */
|
|
||||||
@Column({ nullable: true, name: 'token_reprise', length: 255 })
|
|
||||||
token_reprise?: string;
|
|
||||||
|
|
||||||
@Column({ type: 'timestamptz', nullable: true, name: 'token_reprise_expire_le' })
|
|
||||||
token_reprise_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[];
|
|
||||||
|
|
||||||
@Column({ nullable: true, name: 'relais_id' })
|
|
||||||
relaisId?: string;
|
|
||||||
|
|
||||||
/** Numéro de dossier (format AAAA-NNNNNN), attribué à la soumission (ticket #103) */
|
|
||||||
@Column({ nullable: true, name: 'numero_dossier', length: 20 })
|
|
||||||
numero_dossier?: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Relais, relais => relais.gestionnaires, { nullable: true })
|
|
||||||
@JoinColumn({ name: 'relais_id' })
|
|
||||||
relais?: Relais;
|
|
||||||
}
|
|
||||||
@ -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,67 +0,0 @@
|
|||||||
import { NestFactory } 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 { ValidationPipe } from '@nestjs/common';
|
|
||||||
import { LogRequestInterceptor } from './common/interceptors/log-request.interceptor';
|
|
||||||
|
|
||||||
async function bootstrap() {
|
|
||||||
const app = await NestFactory.create(AppModule,
|
|
||||||
{ logger: ['error', 'warn', 'log', 'debug', 'verbose'] });
|
|
||||||
|
|
||||||
// Log de chaque appel API si LOG_API_REQUESTS=true (mode debug)
|
|
||||||
app.useGlobalInterceptors(new LogRequestInterceptor());
|
|
||||||
|
|
||||||
// Configuration CORS pour autoriser les requêtes depuis localhost (dev) et production
|
|
||||||
app.enableCors({
|
|
||||||
origin: true, // Autorise toutes les origines (dev) - à restreindre en prod
|
|
||||||
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
|
||||||
allowedHeaders: ['Content-Type', 'Authorization', 'Accept'],
|
|
||||||
credentials: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
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,231 +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 {
|
|
||||||
const userId = req.user?.id ?? null;
|
|
||||||
|
|
||||||
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 {}
|
|
||||||
|
|
||||||