forked from Ynov/ptitspas-ynov-back
am can also create acounts for themselves now
This commit is contained in:
parent
0823ffc5cf
commit
cf4bce12eb
@ -29,8 +29,20 @@ export class UserService {
|
|||||||
// Déterminer si le créateur est super admin
|
// Déterminer si le créateur est super admin
|
||||||
const isSuperAdmin = currentUser?.role === RoleType.SUPER_ADMIN;
|
const isSuperAdmin = currentUser?.role === RoleType.SUPER_ADMIN;
|
||||||
|
|
||||||
// Forcer rôle et statut si pas super admin
|
let role: RoleType;
|
||||||
const role = isSuperAdmin ? dto.role : RoleType.PARENT;
|
|
||||||
|
if (isSuperAdmin) {
|
||||||
|
// Un super admin peut créer n'importe quel rôle
|
||||||
|
role = dto.role;
|
||||||
|
} else if (dto.role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||||
|
// Autoriser l'auto-inscription des AM
|
||||||
|
role = RoleType.ASSISTANTE_MATERNELLE;
|
||||||
|
} else {
|
||||||
|
// Tous les autres cas → forcer en PARENT
|
||||||
|
role = RoleType.PARENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Statut par défaut : EN_ATTENTE (sauf si super admin qui peut forcer)
|
||||||
const statut = isSuperAdmin
|
const statut = isSuperAdmin
|
||||||
? dto.statut ?? StatutUtilisateurType.EN_ATTENTE
|
? dto.statut ?? StatutUtilisateurType.EN_ATTENTE
|
||||||
: StatutUtilisateurType.EN_ATTENTE;
|
: StatutUtilisateurType.EN_ATTENTE;
|
||||||
@ -42,17 +54,14 @@ export class UserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vérification des champs obligatoires (déjà couverts par DTO, mais double sécurité)
|
// Vérification des champs obligatoires
|
||||||
if (!dto.nom?.trim()) {
|
if (!dto.nom?.trim()) {
|
||||||
throw new BadRequestException('Nom est obligatoire.');
|
throw new BadRequestException('Nom est obligatoire.');
|
||||||
}
|
} else if (!dto.prenom?.trim()) {
|
||||||
else if (!dto.prenom?.trim()) {
|
|
||||||
throw new BadRequestException('Prénom est obligatoire.');
|
throw new BadRequestException('Prénom est obligatoire.');
|
||||||
}
|
} else if (!dto.adresse?.trim()) {
|
||||||
else if (!dto.adresse?.trim()) {
|
|
||||||
throw new BadRequestException('Adresse est obligatoire.');
|
throw new BadRequestException('Adresse est obligatoire.');
|
||||||
}
|
} else if (!dto.telephone?.trim()) {
|
||||||
else if (!dto.telephone?.trim()) {
|
|
||||||
throw new BadRequestException('Téléphone est obligatoire.');
|
throw new BadRequestException('Téléphone est obligatoire.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +102,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async findAll(): Promise<Users[]> {
|
async findAll(): Promise<Users[]> {
|
||||||
return this.usersRepository.find();
|
return this.usersRepository.find();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user