chore: add register of user
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
|
||||
|
||||
import { UserRepository } from "./users.repository";
|
||||
import { User } from "../entities/user.entity";
|
||||
import { UserMessage } from "../../../common/enums/message.enum";
|
||||
import { RoleRepository } from "./roles.repository";
|
||||
import { UserRepository } from "./users.repository";
|
||||
import { roles } from "../../../../db/seeders/role.seeder";
|
||||
import { UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { User } from "../entities/user.entity";
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -25,4 +26,12 @@ export class UsersService {
|
||||
this.logger.log({ createdRoles });
|
||||
return createdRoles;
|
||||
}
|
||||
|
||||
async createUser(registerDto: CompleteRegistrationDto, hashedPassword: string): Promise<User> {
|
||||
const existEmail = await this.userRepository.findOneWithEmail(registerDto.email);
|
||||
if (existEmail) throw new BadRequestException(UserMessage.EMAIL_EXIST);
|
||||
|
||||
const user = this.userRepository.create({ ...registerDto, password: hashedPassword });
|
||||
return await this.userRepository.save(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user