chore: discount module
This commit is contained in:
@@ -2,13 +2,13 @@ import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import slugify from "slugify";
|
||||
import { In, Not, QueryRunner } from "typeorm";
|
||||
|
||||
import { CommonMessage, FinancialMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CommonMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { UserSettingsService } from "../../settings/providers/user-settings.service";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { WalletsService } from "../../wallets/providers/wallets.service";
|
||||
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
||||
import { CreateFinancialDto } from "../DTO/create-user-financial.dto";
|
||||
// import { CreateFinancialDto } from "../DTO/create-legal-user.dto";
|
||||
import { SearchAdminsDto } from "../DTO/search-admins.dto";
|
||||
import { SearchCustomersDto } from "../DTO/search-customers.dto";
|
||||
import { UpdateProfileDto } from "../DTO/update-profile.dto";
|
||||
@@ -17,7 +17,8 @@ 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 { LegalUserRepository } from "../repositories/legal-user.repository";
|
||||
// import { RealUserRepository } from "../repositories/real-user.repository";
|
||||
import { UserGroupRepository } from "../repositories/user-group.repository";
|
||||
import { UserRepository } from "../repositories/users.repository";
|
||||
|
||||
@@ -41,8 +42,9 @@ export class UsersService {
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly userGroupRepository: UserGroupRepository,
|
||||
private readonly userSettingsService: UserSettingsService,
|
||||
private readonly userFinancialRepository: UserFinancialRepository,
|
||||
private readonly walletsService: WalletsService,
|
||||
// private readonly realUserRepository: RealUserRepository,
|
||||
// private readonly legalUserRepository: LegalUserRepository,
|
||||
) {}
|
||||
|
||||
/************************************************************ */
|
||||
@@ -247,7 +249,8 @@ export class UsersService {
|
||||
if (queryDto.q) {
|
||||
queryBuilder
|
||||
.orWhere("user.firstName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
.orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.userName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
}
|
||||
|
||||
const [customers, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
@@ -273,58 +276,58 @@ export class UsersService {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async createUserFinancial(createDto: CreateFinancialDto, user: User) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: user.role.name === RoleEnum.USER ? user.id : createDto.userId,
|
||||
});
|
||||
// async createRealUserData(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);
|
||||
// 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);
|
||||
// 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);
|
||||
// if (existingFinancial) throw new BadRequestException(FinancialMessage.FINANCIAL_INFO_ALREADY_EXISTS);
|
||||
|
||||
const userFinancial = this.userFinancialRepository.create({
|
||||
...createDto,
|
||||
user: userExist,
|
||||
});
|
||||
// const userFinancial = this.userFinancialRepository.create({
|
||||
// ...createDto,
|
||||
// user: userExist,
|
||||
// });
|
||||
|
||||
await this.userFinancialRepository.save(userFinancial);
|
||||
// await this.userFinancialRepository.save(userFinancial);
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
userFinancial,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// message: CommonMessage.CREATED,
|
||||
// userFinancial,
|
||||
// };
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
// /************************************************************ */
|
||||
|
||||
async updateUserFinancial(updateDto: CreateFinancialDto, user: User, userFinancialId: string) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: user.role.name === RoleEnum.USER ? user.id : updateDto.userId,
|
||||
});
|
||||
// async updateUserFinancial(updateDto: CreateFinancialDto, user: User, userFinancialId: string) {
|
||||
// const userExist = await this.userRepository.findOneBy({
|
||||
// id: user.role.name === RoleEnum.USER ? user.id : updateDto.userId,
|
||||
// });
|
||||
|
||||
if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
// if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const existingFinancial = await this.userFinancialRepository.findOne({
|
||||
where: { id: userFinancialId, user: { id: userExist.id }, type: updateDto.type },
|
||||
});
|
||||
// const existingFinancial = await this.userFinancialRepository.findOne({
|
||||
// where: { id: userFinancialId, user: { id: userExist.id }, type: updateDto.type },
|
||||
// });
|
||||
|
||||
if (!existingFinancial) throw new BadRequestException(FinancialMessage.FINANCIAL_INFO_NOT_FOUND);
|
||||
// if (!existingFinancial) throw new BadRequestException(FinancialMessage.FINANCIAL_INFO_NOT_FOUND);
|
||||
|
||||
await this.userFinancialRepository.save({
|
||||
...existingFinancial,
|
||||
updateDto,
|
||||
});
|
||||
// await this.userFinancialRepository.save({
|
||||
// ...existingFinancial,
|
||||
// updateDto,
|
||||
// });
|
||||
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
userFinancial: existingFinancial,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// message: CommonMessage.UPDATE_SUCCESS,
|
||||
// userFinancial: existingFinancial,
|
||||
// };
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user