refactor: change the role to roles and many to many

This commit is contained in:
mahyargdz
2025-02-16 16:58:51 +03:30
parent 9cdd7ef28e
commit ad673613d9
32 changed files with 264 additions and 88 deletions
+3 -3
View File
@@ -107,13 +107,13 @@ export class UsersService {
/************************************************************ */
async createUser(registerDto: CompleteRegistrationDto, hashedPassword: string, queryRunner: QueryRunner): Promise<User> {
const role = await queryRunner.manager.findOne(Role, { where: { name: RoleEnum.USER } });
const role = await queryRunner.manager.findOneBy(Role, { name: RoleEnum.USER });
if (!role) throw new BadRequestException(UserMessage.ROLE_NOT_FOUND);
const user = queryRunner.manager.create(User, {
...registerDto,
password: hashedPassword,
role,
roles: [role],
});
await queryRunner.manager.save(user);
@@ -264,7 +264,7 @@ export class UsersService {
const customer = await this.userRepository.findOne({
where: {
id: userId,
role: {
roles: {
name: RoleEnum.USER,
},
},