diff --git a/src/routes/user/user.service.ts b/src/routes/user/user.service.ts index 94d2b96..562952c 100644 --- a/src/routes/user/user.service.ts +++ b/src/routes/user/user.service.ts @@ -22,8 +22,8 @@ export class UserService { // Nettoyage / validation consentement photo let consentDate: Date | undefined; - if (dto.consent_photo && dto.consent_photo_at) { - const parsed = new Date(dto.consent_photo_at); + if (dto.consentement_photo && dto.date_consentement_photo) { + const parsed = new Date(dto.date_consentement_photo); if (!isNaN(parsed.getTime())) { consentDate = parsed; } @@ -31,40 +31,38 @@ export class UserService { // Hash mot de passe const salt = await bcrypt.genSalt(); - const password_hash = await bcrypt.hash(dto.password, salt); + const hashedPassword = await bcrypt.hash(dto.password, salt); const entity = this.usersRepository.create({ email: dto.email, - password_hash, - first_name: dto.first_name, - last_name: dto.last_name, + password: hashedPassword, + prenom: dto.prenom, + nom: dto.nom, role: dto.role, - status: dto.status, - gender: dto.gender, - phone: dto.phone, - address: dto.address, + statut: dto.statut, + genre: dto.genre, + telephone: dto.telephone, + ville: dto.ville, + code_postal: dto.code_postal, + adresse: dto.adresse, photo_url: dto.photo_url, - consent_photo: dto.consent_photo ?? false, - consent_photo_at: consentDate, - must_change_password: dto.must_change_password ?? false + consentement_photo: dto.consentement_photo ?? false, + date_consentement_photo: consentDate, + changement_mdp_obligatoire: dto.changement_mdp_obligatoire ?? false }); const saved = await this.usersRepository.save(entity); return this.findOne(saved.id); } - - //Trouver tous les utilisateurs + async findAll(): Promise { return this.usersRepository.find(); } - - // Trouver utilisateur par condition async findOneBy(where: Partial): Promise { return this.usersRepository.findOne({ where }); } - // Trouver utilisateur par ID async findOne(id: string): Promise { const user = await this.usersRepository.findOne({ where: { id } }); if (!user) { @@ -73,12 +71,10 @@ export class UserService { return user; } - // Trouver utilisateur par email async findByEmailOrNull(email: string): Promise { return this.usersRepository.findOne({ where: { email } }); } - // Mettre à jour un utilisateur async updateUser(id: string, dto: UpdateUserDto, currentUser: Users): Promise { const user = await this.findOne(id); @@ -90,23 +86,22 @@ export class UserService { // Gestion du mot de passe if (dto.password) { const salt = await bcrypt.genSalt(); - user.password_hash = await bcrypt.hash(dto.password, salt); + user.password = await bcrypt.hash(dto.password, salt); delete (dto as any).password; } // Conversion de la date de consentement - if (dto.consent_photo_at !== undefined) { - user.consent_photo_at = dto.consent_photo_at - ? new Date(dto.consent_photo_at) + if (dto.date_consentement_photo !== undefined) { + user.date_consentement_photo = dto.date_consentement_photo + ? new Date(dto.date_consentement_photo) : undefined; - delete (dto as any).consent_photo_at; + delete (dto as any).date_consentement_photo; } Object.assign(user, dto); return this.usersRepository.save(user); } - // Supprimer un utilisateur async remove(id: string): Promise { const result = await this.usersRepository.delete(id); if (result.affected === 0) {