added comment to validation
This commit is contained in:
parent
31fc17fd40
commit
dc0e62bac3
@ -57,14 +57,18 @@ export class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/valider')
|
@Patch(':id/valider')
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||||
@ApiOperation({ summary: 'Valider un compte utilisateur' })
|
@ApiOperation({ summary: 'Valider un compte utilisateur' })
|
||||||
|
@ApiParam({ name: 'id', description: "UUID de l'utilisateur" })
|
||||||
|
@ApiResponse({ status: 400, description: 'ID invalide' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Accès refusé' })
|
||||||
@ApiResponse({ status: 200, description: 'Compte validé avec succès' })
|
@ApiResponse({ status: 200, description: 'Compte validé avec succès' })
|
||||||
validerUtilisateur(
|
validerUtilisateur(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() currentUser: Users
|
@User() currentUser: Users,
|
||||||
|
@Body('comment') comment?: string,
|
||||||
) {
|
) {
|
||||||
return this.userService.validateUser(id, currentUser);
|
return this.userService.validateUser(id, currentUser, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,16 @@ import { Repository } from "typeorm";
|
|||||||
import { CreateUserDto } from "./dto/create_user.dto";
|
import { CreateUserDto } from "./dto/create_user.dto";
|
||||||
import { UpdateUserDto } from "./dto/update_user.dto";
|
import { UpdateUserDto } from "./dto/update_user.dto";
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
|
import { StatutValidationType, Validation } from "src/entities/validations.entity";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Users)
|
@InjectRepository(Users)
|
||||||
private readonly usersRepository: Repository<Users>
|
private readonly usersRepository: Repository<Users>,
|
||||||
|
|
||||||
|
@InjectRepository(Validation)
|
||||||
|
private readonly validationRepository: Repository<Validation>
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
// Création utilisateur
|
// Création utilisateur
|
||||||
@ -102,14 +106,26 @@ export class UserService {
|
|||||||
return this.usersRepository.save(user);
|
return this.usersRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateUser(user_id: string, currentUser: Users): Promise<Users> {
|
async validateUser(user_id: string, currentUser: Users, comment?: string): Promise<Users> {
|
||||||
if (![RoleType.SUPER_ADMIN, RoleType.ADMINISTRATEUR, RoleType.GESTIONNAIRE].includes(currentUser.role)) {
|
if (![RoleType.SUPER_ADMIN, RoleType.ADMINISTRATEUR, RoleType.GESTIONNAIRE].includes(currentUser.role)) {
|
||||||
throw new ForbiddenException('Accès réservé aux super admins, administrateurs et gestionnaires');
|
throw new ForbiddenException('Accès réservé aux super admins, administrateurs et gestionnaires');
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.usersRepository.findOne({ where: { id: user_id } });
|
const user = await this.usersRepository.findOne({ where: { id: user_id } });
|
||||||
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
if (!user) throw new NotFoundException('Utilisateur introuvable');
|
||||||
user.statut = StatutUtilisateurType.ACTIF;
|
user.statut = StatutUtilisateurType.ACTIF;
|
||||||
return this.usersRepository.save(user);
|
const savedUser = await this.usersRepository.save(user);
|
||||||
|
|
||||||
|
const validation = this.validationRepository.create({
|
||||||
|
user: savedUser,
|
||||||
|
type: 'validation_compte',
|
||||||
|
status: StatutValidationType.VALIDE,
|
||||||
|
validated_by: currentUser,
|
||||||
|
comment
|
||||||
|
|
||||||
|
});
|
||||||
|
await this.validationRepository.save(validation);
|
||||||
|
return savedUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string): Promise<void> {
|
async remove(id: string): Promise<void> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user