chore: user financial
This commit is contained in:
@@ -2,17 +2,19 @@ import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import slugify from "slugify";
|
||||
import { In, Not, QueryRunner } from "typeorm";
|
||||
|
||||
import { CommonMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CommonMessage, FinancialMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { UserSettingsService } from "../../settings/providers/user-settings.service";
|
||||
import { WalletsService } from "../../wallets/providers/wallets.service";
|
||||
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
||||
import { CreateFinancialDto } from "../DTO/create-user-financial.dto";
|
||||
import { UpdateProfileDto } from "../DTO/update-profile.dto";
|
||||
import { CreateUserGroupDto } from "../DTO/user-group.dto";
|
||||
import { Role } from "../entities/role.entity";
|
||||
import { User } from "../entities/user.entity";
|
||||
import { RoleEnum } from "../enums/role.enum";
|
||||
import { ValidityType } from "../enums/validity-type.enum";
|
||||
import { UserFinancialRepository } from "../repositories/user-financial.repository";
|
||||
import { UserGroupRepository } from "../repositories/user-group.repository";
|
||||
import { UserRepository } from "../repositories/users.repository";
|
||||
|
||||
@@ -36,6 +38,7 @@ export class UsersService {
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly userGroupRepository: UserGroupRepository,
|
||||
private readonly userSettingsService: UserSettingsService,
|
||||
private readonly userFinancialRepository: UserFinancialRepository,
|
||||
private readonly walletsService: WalletsService,
|
||||
) {}
|
||||
|
||||
@@ -121,6 +124,7 @@ export class UsersService {
|
||||
// await this.userSettingsService.createUserSettings(user.id);
|
||||
// return await this.userRepository.save(user);
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async checkValidity(checkDto: CheckValidityDTO, userId: string) {
|
||||
@@ -175,6 +179,7 @@ export class UsersService {
|
||||
}
|
||||
|
||||
///****************************************************** */
|
||||
|
||||
async updateUserPassword(userId: string, newPassword: string) {
|
||||
const updatedUser = await this.userRepository.update(
|
||||
{ id: userId },
|
||||
@@ -186,4 +191,72 @@ export class UsersService {
|
||||
updatedUser,
|
||||
};
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async findAllUsers() {
|
||||
const users = await this.userRepository.find({
|
||||
relations: ["groups"],
|
||||
});
|
||||
|
||||
return { users };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async findAllCustomers() {
|
||||
const customers = await this.userRepository.find({
|
||||
where: {
|
||||
role: {
|
||||
name: RoleEnum.USER,
|
||||
},
|
||||
},
|
||||
relations: ["tickets", "subscriptions", "invoices"],
|
||||
});
|
||||
|
||||
return { customers };
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async createUserFinancial(createDto: CreateFinancialDto, user: User) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: user.role.name === RoleEnum.USER ? user.id : createDto.userId,
|
||||
});
|
||||
|
||||
if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const existingFinancial = await this.userFinancialRepository.findOne({
|
||||
where: { user: { id: userExist.id }, type: createDto.type },
|
||||
});
|
||||
console.log(existingFinancial);
|
||||
|
||||
if (existingFinancial) throw new BadRequestException(FinancialMessage.FINANCIAL_INFO_ALREADY_EXISTS);
|
||||
|
||||
const userFinancial = this.userFinancialRepository.create({
|
||||
...createDto,
|
||||
user: userExist,
|
||||
});
|
||||
|
||||
await this.userFinancialRepository.save(userFinancial);
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
userFinancial,
|
||||
};
|
||||
}
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async getUserFinancial(userId: string) {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
relations: ["userFinancials"],
|
||||
});
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
return { user };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user