Compare commits
No commits in common. "a9c6b9e15b32d0de21e5dfd2bd4f1f7cbf08cd92" and "3c2ecdff7a32338d81f32e42c3ed8217be03e0d0" have entirely different histories.
a9c6b9e15b
...
3c2ecdff7a
@ -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 };
|
|
||||||
}
|
|
||||||
@ -23,7 +23,6 @@ import { ParentsChildren } from 'src/entities/parents_children.entity';
|
|||||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||||
import { LoginDto } from './dto/login.dto';
|
import { LoginDto } from './dto/login.dto';
|
||||||
import { AppConfigService } from 'src/modules/config/config.service';
|
import { AppConfigService } from 'src/modules/config/config.service';
|
||||||
import { validateNir } from 'src/common/utils/nir.util';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@ -326,18 +325,6 @@ export class AuthService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nirNormalized = (dto.nir || '').replace(/\s/g, '').toUpperCase();
|
|
||||||
const nirValidation = validateNir(nirNormalized, {
|
|
||||||
dateNaissance: dto.date_naissance,
|
|
||||||
});
|
|
||||||
if (!nirValidation.valid) {
|
|
||||||
throw new BadRequestException(nirValidation.error || 'NIR invalide');
|
|
||||||
}
|
|
||||||
if (nirValidation.warning) {
|
|
||||||
// Warning uniquement : on ne bloque pas (AM souvent étrangères, DOM-TOM, Corse)
|
|
||||||
console.warn('[inscrireAMComplet] NIR warning:', nirValidation.warning, 'email=', dto.email);
|
|
||||||
}
|
|
||||||
|
|
||||||
const existe = await this.usersService.findByEmailOrNull(dto.email);
|
const existe = await this.usersService.findByEmailOrNull(dto.email);
|
||||||
if (existe) {
|
if (existe) {
|
||||||
throw new ConflictException('Un compte avec cet email existe déjà');
|
throw new ConflictException('Un compte avec cet email existe déjà');
|
||||||
@ -383,7 +370,7 @@ export class AuthService {
|
|||||||
const am = amRepo.create({
|
const am = amRepo.create({
|
||||||
user_id: userEnregistre.id,
|
user_id: userEnregistre.id,
|
||||||
approval_number: dto.numero_agrement,
|
approval_number: dto.numero_agrement,
|
||||||
nir: nirNormalized,
|
nir: dto.nir,
|
||||||
max_children: dto.capacite_accueil,
|
max_children: dto.capacite_accueil,
|
||||||
biography: dto.biographie,
|
biography: dto.biographie,
|
||||||
residence_city: dto.ville ?? undefined,
|
residence_city: dto.ville ?? undefined,
|
||||||
|
|||||||
@ -103,12 +103,10 @@ export class RegisterAMCompletDto {
|
|||||||
@MaxLength(100)
|
@MaxLength(100)
|
||||||
lieu_naissance_pays?: string;
|
lieu_naissance_pays?: string;
|
||||||
|
|
||||||
@ApiProperty({ example: '123456789012345', description: 'NIR 15 caractères (chiffres, ou 2A/2B pour la Corse)' })
|
@ApiProperty({ example: '123456789012345', description: 'NIR 15 chiffres' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty({ message: 'Le NIR est requis' })
|
@IsNotEmpty({ message: 'Le NIR est requis' })
|
||||||
@Matches(/^[1-3]\d{4}(?:2A|2B|\d{2})\d{6}\d{2}$/, {
|
@Matches(/^\d{15}$/, { message: 'Le NIR doit contenir exactement 15 chiffres' })
|
||||||
message: 'Le NIR doit contenir 15 caractères (chiffres, ou 2A/2B pour la Corse)',
|
|
||||||
})
|
|
||||||
nir: string;
|
nir: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'AGR-2024-12345', description: "Numéro d'agrément" })
|
@ApiProperty({ example: 'AGR-2024-12345', description: "Numéro d'agrément" })
|
||||||
|
|||||||
@ -80,7 +80,7 @@ CREATE INDEX idx_utilisateurs_token_creation_mdp
|
|||||||
CREATE TABLE assistantes_maternelles (
|
CREATE TABLE assistantes_maternelles (
|
||||||
id_utilisateur UUID PRIMARY KEY REFERENCES utilisateurs(id) ON DELETE CASCADE,
|
id_utilisateur UUID PRIMARY KEY REFERENCES utilisateurs(id) ON DELETE CASCADE,
|
||||||
numero_agrement VARCHAR(50),
|
numero_agrement VARCHAR(50),
|
||||||
nir_chiffre CHAR(15) NOT NULL,
|
nir_chiffre CHAR(15),
|
||||||
nb_max_enfants INT,
|
nb_max_enfants INT,
|
||||||
biographie TEXT,
|
biographie TEXT,
|
||||||
disponible BOOLEAN DEFAULT true,
|
disponible BOOLEAN DEFAULT true,
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
-- Migration : rendre nir_chiffre NOT NULL (ticket #102)
|
|
||||||
-- À exécuter sur les bases existantes avant déploiement du schéma avec nir_chiffre NOT NULL.
|
|
||||||
-- Les lignes sans NIR reçoivent un NIR de test valide (format + clé) pour satisfaire la contrainte.
|
|
||||||
|
|
||||||
BEGIN;
|
|
||||||
|
|
||||||
-- Renseigner un NIR de test valide pour toute ligne où nir_chiffre est NULL
|
|
||||||
UPDATE assistantes_maternelles
|
|
||||||
SET nir_chiffre = '275119900100102'
|
|
||||||
WHERE nir_chiffre IS NULL;
|
|
||||||
|
|
||||||
-- Appliquer la contrainte NOT NULL
|
|
||||||
ALTER TABLE assistantes_maternelles
|
|
||||||
ALTER COLUMN nir_chiffre SET NOT NULL;
|
|
||||||
|
|
||||||
COMMIT;
|
|
||||||
@ -2,9 +2,6 @@
|
|||||||
-- 03_seed_test_data.sql : Données de test complètes (dashboard admin)
|
-- 03_seed_test_data.sql : Données de test complètes (dashboard admin)
|
||||||
-- Aligné sur utilisateurs-test-complet.json
|
-- Aligné sur utilisateurs-test-complet.json
|
||||||
-- Mot de passe universel : password (bcrypt)
|
-- Mot de passe universel : password (bcrypt)
|
||||||
-- NIR : numéros de test (non réels), cohérents avec les données (date naissance, genre).
|
|
||||||
-- - Marie Dubois : née en Corse à Ajaccio → NIR 2A (test exception Corse).
|
|
||||||
-- - Fatima El Mansouri : née à l'étranger → NIR 99.
|
|
||||||
-- À exécuter après BDD.sql (init DB)
|
-- À exécuter après BDD.sql (init DB)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
@ -39,12 +36,10 @@ VALUES
|
|||||||
ON CONFLICT (id_utilisateur) DO NOTHING;
|
ON CONFLICT (id_utilisateur) DO NOTHING;
|
||||||
|
|
||||||
-- ========== ASSISTANTES MATERNELLES ==========
|
-- ========== ASSISTANTES MATERNELLES ==========
|
||||||
-- Marie Dubois (a0000003) : née en Corse à Ajaccio – NIR 2A pour test exception Corse (1980-06-08, F).
|
|
||||||
-- Fatima El Mansouri (a0000004) : née à l'étranger – NIR 99 pour test (1975-11-12, F).
|
|
||||||
INSERT INTO assistantes_maternelles (id_utilisateur, numero_agrement, nir_chiffre, nb_max_enfants, biographie, date_agrement, ville_residence, disponible, place_disponible)
|
INSERT INTO assistantes_maternelles (id_utilisateur, numero_agrement, nir_chiffre, nb_max_enfants, biographie, date_agrement, ville_residence, disponible, place_disponible)
|
||||||
VALUES
|
VALUES
|
||||||
('a0000003-0003-0003-0003-000000000003', 'AGR-2019-095001', '280062A00100191', 4, 'Assistante maternelle agréée depuis 2019. Née en Corse à Ajaccio. Spécialité bébés 0-18 mois. Accueil bienveillant et cadre sécurisant. 2 places disponibles.', '2019-09-01', 'Bezons', true, 2),
|
('a0000003-0003-0003-0003-000000000003', 'AGR-2019-095001', '280069512345671', 4, 'Assistante maternelle agréée depuis 2019. Spécialité bébés 0-18 mois. Accueil bienveillant et cadre sécurisant. 2 places disponibles.', '2019-09-01', 'Bezons', true, 2),
|
||||||
('a0000004-0004-0004-0004-000000000004', 'AGR-2017-095002', '275119900100102', 3, 'Assistante maternelle expérimentée. Née à l''étranger. Spécialité 1-3 ans. Accueil à la journée. 1 place disponible.', '2017-06-15', 'Bezons', true, 1)
|
('a0000004-0004-0004-0004-000000000004', 'AGR-2017-095002', '275119512345672', 3, 'Assistante maternelle expérimentée. Spécialité 1-3 ans. Accueil à la journée. 1 place disponible.', '2017-06-15', 'Bezons', true, 1)
|
||||||
ON CONFLICT (id_utilisateur) DO NOTHING;
|
ON CONFLICT (id_utilisateur) DO NOTHING;
|
||||||
|
|
||||||
-- ========== ENFANTS ==========
|
-- ========== ENFANTS ==========
|
||||||
|
|||||||
@ -54,15 +54,15 @@ class _AmRegisterStep2ScreenState extends State<AmRegisterStep2Screen> {
|
|||||||
capacity: registrationData.capacity,
|
capacity: registrationData.capacity,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Générer des données de test si les champs sont vides (NIR = Marie Dubois du seed, Corse 2A)
|
// Générer des données de test si les champs sont vides
|
||||||
if (registrationData.dateOfBirth == null && registrationData.nir.isEmpty) {
|
if (registrationData.dateOfBirth == null && registrationData.nir.isEmpty) {
|
||||||
initialData = ProfessionalInfoData(
|
initialData = ProfessionalInfoData(
|
||||||
photoPath: 'assets/images/icon_assmat.png',
|
photoPath: 'assets/images/icon_assmat.png',
|
||||||
photoConsent: true,
|
photoConsent: true,
|
||||||
dateOfBirth: DateTime(1980, 6, 8),
|
dateOfBirth: DateTime(1985, 3, 15),
|
||||||
birthCity: 'Ajaccio',
|
birthCity: DataGenerator.city(),
|
||||||
birthCountry: 'France',
|
birthCountry: 'France',
|
||||||
nir: '280062A00100191',
|
nir: '${DataGenerator.randomIntInRange(1, 3)}${DataGenerator.randomIntInRange(80, 96)}${DataGenerator.randomIntInRange(1, 13).toString().padLeft(2, '0')}${DataGenerator.randomIntInRange(1, 100).toString().padLeft(2, '0')}${DataGenerator.randomIntInRange(100, 1000).toString().padLeft(3, '0')}${DataGenerator.randomIntInRange(100, 1000).toString().padLeft(3, '0')}${DataGenerator.randomIntInRange(10, 100).toString().padLeft(2, '0')}',
|
||||||
agrementNumber: 'AM${DataGenerator.randomIntInRange(10000, 100000)}',
|
agrementNumber: 'AM${DataGenerator.randomIntInRange(10000, 100000)}',
|
||||||
capacity: DataGenerator.randomIntInRange(1, 5),
|
capacity: DataGenerator.randomIntInRange(1, 5),
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user