feat: add payment module and factory
This commit is contained in:
@@ -58,8 +58,6 @@ export class UsersService {
|
||||
/************************************************************ */
|
||||
|
||||
async updateProfile(userId: string, updateProfileDto: UpdateProfileDto) {
|
||||
const { firstName, lastName, birthDate } = updateProfileDto;
|
||||
|
||||
if (updateProfileDto.userName) {
|
||||
updateProfileDto.userName = slugify(updateProfileDto.userName, { lower: true, trim: true });
|
||||
const existUserName = await this.userRepository.findOneBy({ userName: updateProfileDto.userName, id: Not(userId) });
|
||||
@@ -68,13 +66,12 @@ export class UsersService {
|
||||
const user = await this.userRepository.findOneBy({ id: userId });
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const { userName } = updateProfileDto;
|
||||
if (userName) user.userName = userName;
|
||||
if (firstName) user.firstName = firstName;
|
||||
if (lastName) user.lastName = lastName;
|
||||
if (birthDate) user.birthDate = birthDate;
|
||||
// const { userName } = updateProfileDto;
|
||||
// if (userName) user.userName = userName;
|
||||
// if (firstName) user.firstName = firstName;
|
||||
// if (lastName) user.lastName = lastName;
|
||||
|
||||
await this.userRepository.save(user);
|
||||
await this.userRepository.save({ ...user, ...updateProfileDto });
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
};
|
||||
@@ -95,24 +92,17 @@ export class UsersService {
|
||||
/************************************************************ */
|
||||
|
||||
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 queryRunner = this.dataSource.createQueryRunner();
|
||||
|
||||
await queryRunner.connect(); // Establish a connection
|
||||
await queryRunner.startTransaction(); // Start the transaction
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
// Find the USER role
|
||||
const role = await queryRunner.manager.findOne(Role, {
|
||||
where: { name: RoleEnum.USER },
|
||||
});
|
||||
if (!role) {
|
||||
throw new BadRequestException(UserMessage.ROLE_NOT_FOUND);
|
||||
}
|
||||
if (!role) throw new BadRequestException(UserMessage.ROLE_NOT_FOUND);
|
||||
|
||||
// Create and save the User entity
|
||||
const user = queryRunner.manager.create(User, {
|
||||
...registerDto,
|
||||
password: hashedPassword,
|
||||
@@ -122,10 +112,9 @@ export class UsersService {
|
||||
|
||||
await this.userSettingsService.createUserSettings(user.id, queryRunner);
|
||||
|
||||
// Commit the transaction
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return user; // Return the created user
|
||||
return user;
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
@@ -151,6 +140,7 @@ export class UsersService {
|
||||
|
||||
return { message: CommonMessage.VALID_FOR_CHOOSE };
|
||||
}
|
||||
/************************************************************ */
|
||||
|
||||
async createUserGroup(createUserGroupDto: CreateUserGroupDto) {
|
||||
const users = await this.userRepository.find({ where: { id: In(createUserGroupDto.userIds) } });
|
||||
|
||||
Reference in New Issue
Block a user