chore: discount module
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsNotEmpty, IsOptional, IsString, IsUUID } from "class-validator";
|
||||
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class CreateFinancialDto {
|
||||
@ApiPropertyOptional({ description: "Economic code" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
economicCode?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "Registration ID" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.REGISTRATION_ID_INVALID })
|
||||
registrationId?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "number" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.FIXED_PHONE_INVALID })
|
||||
number?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "number" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
nationalId?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "User id", example: "123e4567-e89b-12d3-a456-426614174000" })
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: FinancialMessage.USER_ID_REQUIRED })
|
||||
@IsUUID("4", { message: FinancialMessage.USER_ID_SHOULD_BE_A_UUID })
|
||||
userId: string;
|
||||
}
|
||||
+6
-5
@@ -1,13 +1,14 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from "class-validator";
|
||||
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
import { FinancialType } from "../enums/financial-type.enum";
|
||||
import { GenderType } from "../enums/gender-type.enum";
|
||||
|
||||
export class CreateFinancialDto {
|
||||
@ApiProperty({ enum: FinancialType, description: "Financial information type: REAL or LEGAL" })
|
||||
@IsEnum(FinancialType, { message: FinancialMessage.FINANCIAL_TYPE_INVALID })
|
||||
type: FinancialType;
|
||||
@ApiPropertyOptional({ enum: GenderType, description: "Gender type" })
|
||||
@IsOptional()
|
||||
@IsEnum(GenderType, { message: FinancialMessage.GENDER_TYPE_INVALID })
|
||||
gender?: GenderType;
|
||||
|
||||
@ApiPropertyOptional({ description: "Economic code" })
|
||||
@IsOptional()
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Column, Entity, JoinColumn, OneToOne, Unique } from "typeorm";
|
||||
|
||||
import { User } from "./user.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
|
||||
@Unique(["user"])
|
||||
@Entity()
|
||||
export class LegalUser extends BaseEntity {
|
||||
@Column({ nullable: true })
|
||||
economicCode: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
registrationId: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
nationalId: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
number: string;
|
||||
|
||||
@OneToOne(() => User, (user) => user.legalUser, { onDelete: "CASCADE" })
|
||||
@JoinColumn()
|
||||
user: User;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Column, Entity, JoinColumn, OneToOne, Unique } from "typeorm";
|
||||
|
||||
import { User } from "./user.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { GenderType } from "../enums/gender-type.enum";
|
||||
|
||||
@Unique(["user"])
|
||||
@Entity()
|
||||
export class RealUser extends BaseEntity {
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: GenderType,
|
||||
nullable: true,
|
||||
})
|
||||
gender: GenderType;
|
||||
|
||||
@Column({ nullable: true })
|
||||
fatherName: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
nationality: string;
|
||||
|
||||
@OneToOne(() => User, (user) => user.realUser, { onDelete: "CASCADE" })
|
||||
@JoinColumn()
|
||||
user: User;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import { Column, Entity, ManyToOne, Unique } from "typeorm";
|
||||
|
||||
import { User } from "./user.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { FinancialType } from "../enums/financial-type.enum";
|
||||
|
||||
@Unique(["user", "type"])
|
||||
@Entity()
|
||||
export class UserFinancial extends BaseEntity {
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: FinancialType,
|
||||
default: FinancialType.REAL,
|
||||
})
|
||||
type: FinancialType;
|
||||
|
||||
@Column({ nullable: true })
|
||||
economicCode: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
registrationId: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
nationalId: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
number: string;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.userFinancials)
|
||||
user: User;
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Exclude } from "class-transformer";
|
||||
import { Column, Entity, ManyToMany, ManyToOne, OneToMany, OneToOne } from "typeorm";
|
||||
|
||||
import { LegalUser } from "./legal-user.entity";
|
||||
import { RealUser } from "./real-user.entity";
|
||||
import { Role } from "./role.entity";
|
||||
import { UserFinancial } from "./user-financial.entity";
|
||||
import { UserGroup } from "./user-group.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { UserAnnouncement } from "../../announcements/entities/user-announcement.entity";
|
||||
import { Criticism } from "../../criticisms/entities/criticism.entity";
|
||||
import { Discount } from "../../discounts/entities/discount.entity";
|
||||
import { Invoice } from "../../invoices/entities/invoice.entity";
|
||||
import { LearningProgress } from "../../learnings/entities/learning-progress.entity";
|
||||
import { Notification } from "../../notifications/entities/notification.entity";
|
||||
@@ -84,8 +86,14 @@ export class User extends BaseEntity {
|
||||
@OneToMany(() => LearningProgress, (learningProgress) => learningProgress.learning)
|
||||
learningProgress: LearningProgress[];
|
||||
|
||||
@OneToMany(() => UserFinancial, (userFinancial) => userFinancial.user)
|
||||
userFinancials: UserFinancial[];
|
||||
@ManyToMany(() => Discount, (discount) => discount.subscriptionPlans)
|
||||
discounts: Discount[];
|
||||
|
||||
@OneToOne(() => RealUser, (realUser) => realUser.user, { cascade: true, nullable: true })
|
||||
realUser: RealUser;
|
||||
|
||||
@OneToOne(() => LegalUser, (legalUser) => legalUser.user, { cascade: true, nullable: true })
|
||||
legalUser: LegalUser;
|
||||
}
|
||||
|
||||
// @ManyToMany(() => DanakService, (danakService) => danakService.users)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum GenderType {
|
||||
MALE = "male",
|
||||
FEMALE = "female",
|
||||
}
|
||||
@@ -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,
|
||||
// };
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { LegalUser } from "../entities/legal-user.entity";
|
||||
|
||||
@Injectable()
|
||||
export class LegalUserRepository extends Repository<LegalUser> {
|
||||
constructor(@InjectRepository(LegalUser) LegalUserRepository: Repository<LegalUser>) {
|
||||
super(LegalUserRepository.target, LegalUserRepository.manager, LegalUserRepository.queryRunner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { RealUser } from "../entities/real-user.entity";
|
||||
|
||||
@Injectable()
|
||||
export class RealUserRepository extends Repository<RealUser> {
|
||||
constructor(@InjectRepository(RealUser) realUserRepository: Repository<RealUser>) {
|
||||
super(realUserRepository.target, realUserRepository.manager, realUserRepository.queryRunner);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { UserFinancial } from "../entities/user-financial.entity";
|
||||
|
||||
@Injectable()
|
||||
export class UserFinancialRepository extends Repository<UserFinancial> {
|
||||
constructor(@InjectRepository(UserFinancial) userFinancialRepository: Repository<UserFinancial>) {
|
||||
super(userFinancialRepository.target, userFinancialRepository.manager, userFinancialRepository.queryRunner);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Patch, Post, Query } from "@nestjs/common";
|
||||
import { Body, Controller, Get, HttpCode, HttpStatus, Patch, Post, Query } from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
|
||||
import { CheckValidityDTO } from "./DTO/check-validity.dto";
|
||||
import { CreateFinancialDto } from "./DTO/create-user-financial.dto";
|
||||
import { SearchAdminsDto } from "./DTO/search-admins.dto";
|
||||
import { SearchCustomersDto } from "./DTO/search-customers.dto";
|
||||
import { UpdateProfileDto } from "./DTO/update-profile.dto";
|
||||
@@ -13,7 +12,6 @@ import { UsersService } from "./providers/users.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { Roles } from "../../common/decorators/roles.decorator";
|
||||
import { UserDec } from "../../common/decorators/user.decorator";
|
||||
import { ParamDto } from "../../common/DTO/param.dto";
|
||||
|
||||
@Controller("users")
|
||||
@ApiTags("users")
|
||||
@@ -91,23 +89,23 @@ export class UsersController {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
@AuthGuards()
|
||||
@ApiOperation({ summary: "Create user financial" })
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Post("user-financial")
|
||||
createUserFinancial(@Body() createDto: CreateFinancialDto, @UserDec() user: User) {
|
||||
return this.usersService.createUserFinancial(createDto, user);
|
||||
}
|
||||
// @AuthGuards()
|
||||
// @ApiOperation({ summary: "Create user financial" })
|
||||
// @HttpCode(HttpStatus.CREATED)
|
||||
// @Post("user-financial")
|
||||
// createUserFinancial(@Body() createDto: CreateFinancialDto, @UserDec() user: User) {
|
||||
// return this.usersService.createUserFinancial(createDto, user);
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
@AuthGuards()
|
||||
@ApiOperation({ summary: "update user financial" })
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Patch("user-financial/:id/update")
|
||||
updateUserFinancial(@Body() updateDto: CreateFinancialDto, @UserDec() user: User, @Param() paramDto: ParamDto) {
|
||||
return this.usersService.updateUserFinancial(updateDto, user, paramDto.id);
|
||||
}
|
||||
// @AuthGuards()
|
||||
// @ApiOperation({ summary: "update user financial" })
|
||||
// @HttpCode(HttpStatus.CREATED)
|
||||
// @Patch("user-financial/:id/update")
|
||||
// updateUserFinancial(@Body() updateDto: CreateFinancialDto, @UserDec() user: User, @Param() paramDto: ParamDto) {
|
||||
// return this.usersService.updateUserFinancial(updateDto, user, paramDto.id);
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { LegalUser } from "./entities/legal-user.entity";
|
||||
import { Role } from "./entities/role.entity";
|
||||
import { UserGroup } from "./entities/user-group.entity";
|
||||
import { User } from "./entities/user.entity";
|
||||
import { UsersService } from "./providers/users.service";
|
||||
import { LegalUserRepository } from "./repositories/legal-user.repository";
|
||||
import { RoleRepository } from "./repositories/roles.repository";
|
||||
import { UserGroupRepository } from "./repositories/user-group.repository";
|
||||
import { UserRepository } from "./repositories/users.repository";
|
||||
@@ -13,21 +15,22 @@ import { UserSetting } from "../settings/entities/user-setting.entity";
|
||||
import { UserSettingsService } from "../settings/providers/user-settings.service";
|
||||
import { UserSettingsRepository } from "../settings/repositories/user-settings.repository";
|
||||
import { WalletsModule } from "../wallets/wallets.module";
|
||||
import { UserFinancial } from "./entities/user-financial.entity";
|
||||
import { UserFinancialRepository } from "./repositories/user-financial.repository";
|
||||
import { RealUser } from "./entities/real-user.entity";
|
||||
import { RealUserRepository } from "./repositories/real-user.repository";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User, Role, UserGroup, UserSetting, UserFinancial]), WalletsModule],
|
||||
imports: [TypeOrmModule.forFeature([User, Role, UserGroup, UserSetting, RealUser, LegalUser]), WalletsModule],
|
||||
providers: [
|
||||
UsersService,
|
||||
UserRepository,
|
||||
RoleRepository,
|
||||
UserGroupRepository,
|
||||
UserSettingsRepository,
|
||||
UserFinancialRepository,
|
||||
UserSettingsService,
|
||||
RealUserRepository,
|
||||
LegalUserRepository,
|
||||
],
|
||||
controllers: [UsersController],
|
||||
exports: [UsersService],
|
||||
exports: [UsersService, TypeOrmModule, UserRepository],
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
||||
Reference in New Issue
Block a user