feat: add payment module and factory
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Exclude } from "class-transformer";
|
||||
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany } from "typeorm";
|
||||
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany, OneToOne } from "typeorm";
|
||||
|
||||
import { Role } from "./role.entity";
|
||||
import { UserGroup } from "./user-group.entity";
|
||||
@@ -7,9 +7,11 @@ import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { UserAnnouncement } from "../../announcements/entities/user-announcement.entity";
|
||||
import { Criticism } from "../../criticisms/entities/criticism.entity";
|
||||
import { DanakService } from "../../danak-services/entities/danak-service.entity";
|
||||
import { Payment } from "../../payments/entities/payment.entity";
|
||||
import { UserSetting } from "../../settings/entities/user-setting.entity";
|
||||
import { TicketMessage } from "../../tickets/entities/ticket-message.entity";
|
||||
import { Ticket } from "../../tickets/entities/ticket.entity";
|
||||
import { Wallet } from "../../wallets/entities/wallet.entity";
|
||||
|
||||
@Entity()
|
||||
export class User extends BaseEntity {
|
||||
@@ -62,4 +64,9 @@ export class User extends BaseEntity {
|
||||
|
||||
@OneToMany(() => UserSetting, (settings) => settings.user, { nullable: false })
|
||||
settings: UserSetting;
|
||||
@OneToOne(() => Wallet, (wallet) => wallet.user)
|
||||
wallet: Wallet;
|
||||
|
||||
@OneToMany(() => Payment, (payment) => payment.user)
|
||||
payments: Payment[];
|
||||
}
|
||||
|
||||
@@ -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) } });
|
||||
|
||||
@@ -17,7 +17,7 @@ import { UserSettingsRepository } from "../settings/repositories/user-settings.r
|
||||
imports: [TypeOrmModule.forFeature([User, Role, UserGroup, UserSetting])],
|
||||
providers: [UsersService, UserRepository, RoleRepository, UserGroupRepository, UserSettingsRepository, UserSettingsService],
|
||||
controllers: [UsersController],
|
||||
exports: [UsersService, TypeOrmModule],
|
||||
exports: [UsersService],
|
||||
})
|
||||
export class UsersModule implements OnApplicationBootstrap {
|
||||
// constructor(private userService: UsersService) {}
|
||||
|
||||
Reference in New Issue
Block a user