chore: change the real user abd legal user data
This commit is contained in:
@@ -85,6 +85,14 @@ export const enum UserMessage {
|
|||||||
CITY_REQUIRED = "شهر نمیتواند خالی باشد",
|
CITY_REQUIRED = "شهر نمیتواند خالی باشد",
|
||||||
CITY_NOT_FOUND = "شهر یافت نشد",
|
CITY_NOT_FOUND = "شهر یافت نشد",
|
||||||
CITY_SHOULD_BE_UUID = "شناسه شهر باید یک UUID باشد",
|
CITY_SHOULD_BE_UUID = "شناسه شهر باید یک UUID باشد",
|
||||||
|
REAL_DATA_EXIST = "اطلاعات حقیقی قبلا ثبت شده است",
|
||||||
|
LEGAL_DATA_EXIST = "اطلاعات حقوقی قبلا ثبت شده است",
|
||||||
|
ECONOMIC_CODE_EXIST = "کد اقتصادی قبلا ثبت شده است",
|
||||||
|
REGISTRATION_CODE_EXIST = "کد ثبت قبلا ثبت شده است",
|
||||||
|
NATIONAL_IDENTITY_EXIST = "شناسه ملی قبلا ثبت شده است",
|
||||||
|
PHONE_SHOULD_BE_11_DIGIT = "شماره تلفن باید ۱۱ رقم باشد",
|
||||||
|
FINANCIAL_TYPE_IS_LEGAL = "نوع کاربر حقوقی میباشد",
|
||||||
|
FINANCIAL_TYPE_IS_REAL = "نوع کاربر حقیقی میباشد",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum CommonMessage {
|
export const enum CommonMessage {
|
||||||
@@ -485,6 +493,20 @@ export const enum FinancialMessage {
|
|||||||
BIRTH_DATE_REQUIRED = "تاریخ تولد مورد نیاز است",
|
BIRTH_DATE_REQUIRED = "تاریخ تولد مورد نیاز است",
|
||||||
ADDRESS_STRING = "آدرس باید یک رشته باشد",
|
ADDRESS_STRING = "آدرس باید یک رشته باشد",
|
||||||
POSTAL_CODE_NUMBER_STRING = "کد پستی باید یک رشته عددی باشد",
|
POSTAL_CODE_NUMBER_STRING = "کد پستی باید یک رشته عددی باشد",
|
||||||
|
ECONOMIC_CODE_REQUIRED = "کد اقتصادی مورد نیاز است",
|
||||||
|
ECONOMIC_CODE_INVALID = "کد اقتصادی نامعتبر است",
|
||||||
|
REGISTRATION_CODE_REQUIRED = "کد ثبت مورد نیاز است",
|
||||||
|
REGISTRATION_ID_INVALID = "شناسه ثبت نامعتبر است",
|
||||||
|
REGISTRATION_NAME_REQUIRED = "نام ثبت شده مورد نیاز است",
|
||||||
|
REGISTRATION_NAME_INVALID = "نام ثبت شده نامعتبر است",
|
||||||
|
NATIONAL_ID_REQUIRED = "شناسه ملی مورد نیاز است",
|
||||||
|
NATIONAL_ID_INVALID = "شناسه ملی نامعتبر است",
|
||||||
|
ECONOMIC_CODE_STRING = "کد اقتصادی باید یک رشته باشد",
|
||||||
|
REGISTRATION_ID_STRING = "شناسه ثبت باید یک رشته باشد",
|
||||||
|
REGISTRATION_NAME_STRING = "نام ثبت شده باید یک رشته باشد",
|
||||||
|
NATIONAL_ID_STRING = "شناسه ملی باید یک رشته باشد",
|
||||||
|
ECONOMIC_CODE_NUMBER_STRING = "کد اقتصادی باید یک رشته عددی باشد",
|
||||||
|
REGISTRATION_ID_NUMBER_STRING = "شناسه ثبت باید یک رشته عددی باشد",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum AdminMessage {
|
export const enum AdminMessage {
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ export class Address extends BaseEntity {
|
|||||||
postalCode: string;
|
postalCode: string;
|
||||||
|
|
||||||
@Column({ type: "text" })
|
@Column({ type: "text" })
|
||||||
address: string;
|
fullAddress: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ export class City {
|
|||||||
@Column({ type: "varchar", length: 255 })
|
@Column({ type: "varchar", length: 255 })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@ManyToOne(() => Province, (province) => province.cities, { nullable: false })
|
@ManyToOne(() => Province, (province) => province.cities, { eager: true, nullable: false })
|
||||||
province: Province;
|
province: Province;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export class AddressService {
|
|||||||
private readonly cityRepository: CityRepository,
|
private readonly cityRepository: CityRepository,
|
||||||
private readonly provinceRepository: ProvinceRepository,
|
private readonly provinceRepository: ProvinceRepository,
|
||||||
) {}
|
) {}
|
||||||
|
//*********************************** */
|
||||||
|
|
||||||
async getAllCities(queryDto: SearchCitiesDto) {
|
async getAllCities(queryDto: SearchCitiesDto) {
|
||||||
const { limit, skip } = PaginationUtils(queryDto);
|
const { limit, skip } = PaginationUtils(queryDto);
|
||||||
@@ -32,6 +33,7 @@ export class AddressService {
|
|||||||
paginate: true,
|
paginate: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
//*********************************** */
|
||||||
|
|
||||||
async getAllProvinces(queryDto: SearchCitiesDto) {
|
async getAllProvinces(queryDto: SearchCitiesDto) {
|
||||||
const { limit, skip } = PaginationUtils(queryDto);
|
const { limit, skip } = PaginationUtils(queryDto);
|
||||||
@@ -52,6 +54,7 @@ export class AddressService {
|
|||||||
paginate: true,
|
paginate: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
//*********************************** */
|
||||||
|
|
||||||
async getProvince(id: number) {
|
async getProvince(id: number) {
|
||||||
const province = await this.provinceRepository.findOneBy({
|
const province = await this.provinceRepository.findOneBy({
|
||||||
@@ -61,25 +64,25 @@ export class AddressService {
|
|||||||
|
|
||||||
return { province };
|
return { province };
|
||||||
}
|
}
|
||||||
|
//*********************************** */
|
||||||
|
|
||||||
async getCity(id: number) {
|
async getCity(id: number) {
|
||||||
const city = await this.cityRepository.findOneBy({
|
const city = await this.cityRepository.findOneBy({ id });
|
||||||
id,
|
|
||||||
});
|
|
||||||
if (!city) throw new BadRequestException(CityMessage.NOT_FOUND);
|
if (!city) throw new BadRequestException(CityMessage.NOT_FOUND);
|
||||||
|
|
||||||
return { city };
|
return { city };
|
||||||
}
|
}
|
||||||
|
//*********************************** */
|
||||||
|
|
||||||
async getCitiesByProvince(queryDto: SearchCitiesDto, id: number) {
|
async getCitiesByProvince(queryDto: SearchCitiesDto, id: number) {
|
||||||
const { limit, skip } = PaginationUtils(queryDto);
|
const { limit, skip } = PaginationUtils(queryDto);
|
||||||
|
|
||||||
const province = await this.provinceRepository.findOneBy({
|
const province = await this.provinceRepository.findOneBy({ id });
|
||||||
id,
|
|
||||||
});
|
|
||||||
if (!province) throw new BadRequestException(CityMessage.NOT_FOUND);
|
if (!province) throw new BadRequestException(CityMessage.NOT_FOUND);
|
||||||
|
|
||||||
const queryBuilder = this.cityRepository.createQueryBuilder("city").where("city.provinceId = :provinceId", { provinceId: province.id });
|
const queryBuilder = this.cityRepository.createQueryBuilder("city").where("city.provinceId = :provinceId", { provinceId: province.id });
|
||||||
|
|
||||||
|
//
|
||||||
if (queryDto.q) {
|
if (queryDto.q) {
|
||||||
queryBuilder.andWhere("city.name ILIKE :q", { q: `%${queryDto.q}%` });
|
queryBuilder.andWhere("city.name ILIKE :q", { q: `%${queryDto.q}%` });
|
||||||
}
|
}
|
||||||
@@ -94,15 +97,9 @@ export class AddressService {
|
|||||||
pagination: true,
|
pagination: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
//*********************************** */
|
||||||
async getProvinceByCity(id: number) {
|
async getProvinceByCity(id: number) {
|
||||||
const province = await this.provinceRepository.findOne({
|
const province = await this.provinceRepository.findOne({ where: { cities: { id } } });
|
||||||
where: {
|
|
||||||
cities: {
|
|
||||||
id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (!province) throw new BadRequestException(ProvinceMessage.NOT_FOUND);
|
if (!province) throw new BadRequestException(ProvinceMessage.NOT_FOUND);
|
||||||
|
|
||||||
return { province };
|
return { province };
|
||||||
|
|||||||
@@ -477,6 +477,7 @@ export class InvoicesService {
|
|||||||
const invoiceCount = await this.invoiceRepository.count({
|
const invoiceCount = await this.invoiceRepository.count({
|
||||||
where: {
|
where: {
|
||||||
user: { id: userId },
|
user: { id: userId },
|
||||||
|
status: InvoiceStatus.WAIT_PAYMENT,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return invoiceCount;
|
return invoiceCount;
|
||||||
|
|||||||
@@ -1,46 +1,28 @@
|
|||||||
// import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
import { ApiProperty, PickType } from "@nestjs/swagger";
|
||||||
// import { IsNotEmpty, IsOptional, IsString } from "class-validator";
|
import { IsNotEmpty, IsNumberString, IsString } from "class-validator";
|
||||||
|
|
||||||
// import { FinancialMessage } from "../../../common/enums/message.enum";
|
import { CreateRealUserDto } from "./create-real-user.dto";
|
||||||
|
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||||
|
|
||||||
// export class CreateLegalUserDto {
|
//TODO:fix the validation
|
||||||
// @ApiProperty({ description: "Economic code" })
|
export class CreateLegalUserDto extends PickType(CreateRealUserDto, ["phone", "address", "postalCode", "cityId"] as const) {
|
||||||
// @IsOptional()
|
@IsNotEmpty({ message: FinancialMessage.ECONOMIC_CODE_REQUIRED })
|
||||||
// @IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
@IsNumberString({ no_symbols: true }, { message: FinancialMessage.ECONOMIC_CODE_NUMBER_STRING })
|
||||||
// economicCode?: string;
|
@ApiProperty({ description: "Economic code" })
|
||||||
|
economicCode: string;
|
||||||
|
|
||||||
// @ApiProperty({ description: "Company registered name" })
|
@IsNotEmpty({ message: FinancialMessage.REGISTRATION_CODE_REQUIRED })
|
||||||
// @IsOptional()
|
@IsNumberString({ no_symbols: true }, { message: FinancialMessage.REGISTRATION_ID_NUMBER_STRING })
|
||||||
// @IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
@ApiProperty({ description: "Registration code" })
|
||||||
// companyRegisteredName?: string;
|
registrationCode: string;
|
||||||
|
|
||||||
// @ApiProperty({ description: "Registration ID" })
|
@IsNotEmpty({ message: FinancialMessage.REGISTRATION_NAME_REQUIRED })
|
||||||
// @IsOptional()
|
@IsString({ message: FinancialMessage.REGISTRATION_NAME_STRING })
|
||||||
// @IsString({ message: FinancialMessage.REGISTRATION_ID_INVALID })
|
@ApiProperty({ description: "Registration name" })
|
||||||
// registrationId?: string;
|
registrationName: string;
|
||||||
|
|
||||||
// @ApiProperty({ description: "national Id" })
|
@IsNotEmpty({ message: FinancialMessage.NATIONAL_ID_REQUIRED })
|
||||||
// @IsOptional()
|
@IsString({ message: FinancialMessage.NATIONAL_ID_STRING })
|
||||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
@ApiProperty({ description: "National identity" })
|
||||||
// nationalId?: string;
|
nationalIdentity: string;
|
||||||
|
}
|
||||||
// @ApiPropertyOptional({ description: "number" })
|
|
||||||
// @IsOptional()
|
|
||||||
// @IsString({ message: FinancialMessage.FIXED_PHONE_INVALID })
|
|
||||||
// number?: string;
|
|
||||||
|
|
||||||
// @ApiPropertyOptional({ description: "postalCode" })
|
|
||||||
// @IsOptional()
|
|
||||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
|
||||||
// postalCode?: string;
|
|
||||||
|
|
||||||
// @ApiPropertyOptional({ description: "address" })
|
|
||||||
// @IsOptional()
|
|
||||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
|
||||||
// address?: string;
|
|
||||||
|
|
||||||
// @ApiPropertyOptional({ description: "City id", example: "1" })
|
|
||||||
// @IsOptional()
|
|
||||||
// @IsNotEmpty({ message: FinancialMessage.CITY_ID_REQUIRED })
|
|
||||||
// cityId: string;
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger";
|
import { ApiProperty, PickType } from "@nestjs/swagger";
|
||||||
import { IsEnum, IsInt, IsNotEmpty, IsNumberString, IsString } from "class-validator";
|
import { IsEnum, IsInt, IsNotEmpty, IsNumberString, IsString } from "class-validator";
|
||||||
|
|
||||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||||
|
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||||
import { GenderEnum } from "../enums/gender-type.enum";
|
import { GenderEnum } from "../enums/gender-type.enum";
|
||||||
import { NationalityEnum } from "../enums/nationality.enum";
|
import { NationalityEnum } from "../enums/nationality.enum";
|
||||||
|
|
||||||
export class CreateRealUserDto {
|
export class CreateRealUserDto extends PickType(CompleteRegistrationDto, ["firstName", "lastName", "birthDate", "nationalCode", "phone"]) {
|
||||||
@IsNotEmpty({ message: FinancialMessage.GENDER_TYPE_REQUIRED })
|
@IsNotEmpty({ message: FinancialMessage.GENDER_TYPE_REQUIRED })
|
||||||
@IsEnum(GenderEnum)
|
@IsEnum(GenderEnum)
|
||||||
@ApiProperty({ enum: GenderEnum, description: "Gender type", example: GenderEnum.MALE })
|
@ApiProperty({ enum: GenderEnum, description: "Gender type", example: GenderEnum.MALE })
|
||||||
@@ -19,8 +20,9 @@ export class CreateRealUserDto {
|
|||||||
@IsNotEmpty({ message: FinancialMessage.NATIONALITY_REQUIRED })
|
@IsNotEmpty({ message: FinancialMessage.NATIONALITY_REQUIRED })
|
||||||
@IsEnum(NationalityEnum)
|
@IsEnum(NationalityEnum)
|
||||||
@ApiProperty({ description: "Nationality" })
|
@ApiProperty({ description: "Nationality" })
|
||||||
nationality: string;
|
nationality: NationalityEnum;
|
||||||
|
|
||||||
|
//for address entity
|
||||||
@IsNotEmpty({ message: FinancialMessage.ADDRESS_REQUIRED })
|
@IsNotEmpty({ message: FinancialMessage.ADDRESS_REQUIRED })
|
||||||
@IsString({ message: FinancialMessage.ADDRESS_STRING })
|
@IsString({ message: FinancialMessage.ADDRESS_STRING })
|
||||||
@ApiProperty({ description: "Address" })
|
@ApiProperty({ description: "Address" })
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
import { Column, Entity, JoinColumn, OneToOne, Unique } from "typeorm";
|
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
|
||||||
|
|
||||||
import { User } from "./user.entity";
|
import { User } from "./user.entity";
|
||||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||||
import { Address } from "../../address/entities/address.entity";
|
import { Address } from "../../address/entities/address.entity";
|
||||||
|
|
||||||
@Unique(["user"])
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class LegalUser extends BaseEntity {
|
export class LegalUser extends BaseEntity {
|
||||||
@Column({ type: "varchar", length: 50, nullable: true })
|
@Column({ type: "varchar", length: 50, unique: true })
|
||||||
economicCode: string;
|
economicCode: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", length: 50, nullable: true })
|
@Column({ type: "varchar", length: 50, unique: true })
|
||||||
registrationId: string;
|
registrationCode: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", length: 100, nullable: true })
|
@Column({ type: "varchar", length: 100, unique: true })
|
||||||
companyRegisteredName: string;
|
registrationName: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", length: 20, nullable: true })
|
@Column({ type: "varchar", length: 20, unique: true })
|
||||||
nationalId: string;
|
nationalIdentity: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", length: 20, nullable: true })
|
@Column({ type: "varchar", length: 20, unique: true })
|
||||||
number: string;
|
phone: string;
|
||||||
|
|
||||||
@OneToOne(() => Address, { nullable: false, cascade: true })
|
@OneToOne(() => Address, { nullable: false, cascade: true })
|
||||||
@JoinColumn()
|
@JoinColumn()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Column, Entity, JoinColumn, OneToOne, Unique } from "typeorm";
|
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
|
||||||
|
|
||||||
import { User } from "./user.entity";
|
import { User } from "./user.entity";
|
||||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||||
@@ -6,7 +6,6 @@ import { Address } from "../../address/entities/address.entity";
|
|||||||
import { GenderEnum } from "../enums/gender-type.enum";
|
import { GenderEnum } from "../enums/gender-type.enum";
|
||||||
import { NationalityEnum } from "../enums/nationality.enum";
|
import { NationalityEnum } from "../enums/nationality.enum";
|
||||||
|
|
||||||
@Unique(["user"])
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class RealUser extends BaseEntity {
|
export class RealUser extends BaseEntity {
|
||||||
@Column({ type: "varchar", length: 150 })
|
@Column({ type: "varchar", length: 150 })
|
||||||
|
|||||||
@@ -1,27 +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;
|
|
||||||
}
|
|
||||||
@@ -21,6 +21,7 @@ import { UserSubscription } from "../../subscriptions/entities/user-subscription
|
|||||||
import { TicketMessage } from "../../tickets/entities/ticket-message.entity";
|
import { TicketMessage } from "../../tickets/entities/ticket-message.entity";
|
||||||
import { Ticket } from "../../tickets/entities/ticket.entity";
|
import { Ticket } from "../../tickets/entities/ticket.entity";
|
||||||
import { Wallet } from "../../wallets/entities/wallet.entity";
|
import { Wallet } from "../../wallets/entities/wallet.entity";
|
||||||
|
import { FinancialType } from "../enums/financial-type.enum";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User extends BaseEntity {
|
export class User extends BaseEntity {
|
||||||
@@ -55,6 +56,9 @@ export class User extends BaseEntity {
|
|||||||
@Column({ type: "boolean", default: false })
|
@Column({ type: "boolean", default: false })
|
||||||
emailVerified: boolean;
|
emailVerified: boolean;
|
||||||
|
|
||||||
|
@Column({ type: "enum", enum: FinancialType, nullable: true })
|
||||||
|
financialType: FinancialType | null;
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
@ManyToMany(() => Role, (role) => role.users)
|
@ManyToMany(() => Role, (role) => role.users)
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import { WalletsService } from "../../wallets/providers/wallets.service";
|
|||||||
import { ChangeEmailDto } from "../DTO/change-email.dto";
|
import { ChangeEmailDto } from "../DTO/change-email.dto";
|
||||||
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
import { CheckValidityDTO } from "../DTO/check-validity.dto";
|
||||||
import { CreateAdminDto } from "../DTO/create-admin.dto";
|
import { CreateAdminDto } from "../DTO/create-admin.dto";
|
||||||
|
import { CreateLegalUserDto } from "../DTO/create-legal-user.dto";
|
||||||
|
import { CreateRealUserDto } from "../DTO/create-real-user.dto";
|
||||||
import { CreateRoleDto } from "../DTO/create-role.dto";
|
import { CreateRoleDto } from "../DTO/create-role.dto";
|
||||||
import { SearchAdminQueryDto } from "../DTO/search-admins-query.dto";
|
import { SearchAdminQueryDto } from "../DTO/search-admins-query.dto";
|
||||||
import { SearchRolesQueryDto } from "../DTO/search-roles.dto";
|
import { SearchRolesQueryDto } from "../DTO/search-roles.dto";
|
||||||
@@ -30,9 +32,12 @@ import { CreateUserGroupDto } from "../DTO/user-group.dto";
|
|||||||
import { EmailVerifyQueryDto } from "../DTO/verify-email-query.dto";
|
import { EmailVerifyQueryDto } from "../DTO/verify-email-query.dto";
|
||||||
import { Role } from "../entities/role.entity";
|
import { Role } from "../entities/role.entity";
|
||||||
import { User } from "../entities/user.entity";
|
import { User } from "../entities/user.entity";
|
||||||
|
import { FinancialType } from "../enums/financial-type.enum";
|
||||||
import { RoleEnum } from "../enums/role.enum";
|
import { RoleEnum } from "../enums/role.enum";
|
||||||
import { ValidityType } from "../enums/validity-type.enum";
|
import { ValidityType } from "../enums/validity-type.enum";
|
||||||
|
import { LegalUserRepository } from "../repositories/legal-user.repository";
|
||||||
import { PermissionsRepository } from "../repositories/permissions.repository";
|
import { PermissionsRepository } from "../repositories/permissions.repository";
|
||||||
|
import { RealUserRepository } from "../repositories/real-user.repository";
|
||||||
import { RoleRepository } from "../repositories/roles.repository";
|
import { RoleRepository } from "../repositories/roles.repository";
|
||||||
import { UserGroupRepository } from "../repositories/user-group.repository";
|
import { UserGroupRepository } from "../repositories/user-group.repository";
|
||||||
import { UserRepository } from "../repositories/users.repository";
|
import { UserRepository } from "../repositories/users.repository";
|
||||||
@@ -49,6 +54,8 @@ export class UsersService {
|
|||||||
private readonly permissionsRepository: PermissionsRepository,
|
private readonly permissionsRepository: PermissionsRepository,
|
||||||
private readonly passwordService: PasswordService,
|
private readonly passwordService: PasswordService,
|
||||||
private readonly addressService: AddressService,
|
private readonly addressService: AddressService,
|
||||||
|
private readonly realUserRepository: RealUserRepository,
|
||||||
|
private readonly legalUserRepository: LegalUserRepository,
|
||||||
private readonly emailService: EmailService,
|
private readonly emailService: EmailService,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly otpService: OTPService,
|
private readonly otpService: OTPService,
|
||||||
@@ -81,20 +88,22 @@ export class UsersService {
|
|||||||
|
|
||||||
/************************************************************ */
|
/************************************************************ */
|
||||||
|
|
||||||
async getMyFinancialInfo(userId: string) {
|
async getRealUserData(userId: string) {
|
||||||
const user = await this.userRepository
|
const realUser = await this.realUserRepository.findOne({
|
||||||
.createQueryBuilder("user")
|
where: { user: { id: userId } },
|
||||||
.leftJoinAndSelect("user.address", "address")
|
relations: { address: { city: { province: true } } },
|
||||||
.leftJoinAndSelect("address.city", "city")
|
});
|
||||||
.leftJoinAndSelect("city.province", "province")
|
return { realUser };
|
||||||
.leftJoinAndSelect("user.realUser", "realUser")
|
|
||||||
.leftJoinAndSelect("user.legalUser", "legalUser")
|
|
||||||
.where("user.id = :id", { id: userId })
|
|
||||||
.getOne();
|
|
||||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
|
||||||
return { user };
|
|
||||||
}
|
}
|
||||||
|
/************************************************************ */
|
||||||
|
|
||||||
|
async getLegalUserData(userId: string) {
|
||||||
|
const legalUser = await this.legalUserRepository.findOne({
|
||||||
|
where: { user: { id: userId } },
|
||||||
|
relations: { address: { city: { province: true } } },
|
||||||
|
});
|
||||||
|
return { legalUser };
|
||||||
|
}
|
||||||
/************************************************************ */
|
/************************************************************ */
|
||||||
|
|
||||||
async updateProfile(userId: string, updateProfileDto: UpdateProfileDto) {
|
async updateProfile(userId: string, updateProfileDto: UpdateProfileDto) {
|
||||||
@@ -487,7 +496,10 @@ export class UsersService {
|
|||||||
name: RoleEnum.USER,
|
name: RoleEnum.USER,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
relations: ["legalUser", "realUser"],
|
relations: {
|
||||||
|
legalUser: true,
|
||||||
|
realUser: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return { customer };
|
return { customer };
|
||||||
@@ -564,75 +576,94 @@ export class UsersService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
/************************************************************ */
|
/************************************************************ */
|
||||||
|
//TODO:query manager
|
||||||
|
async createRealUserData(createDto: CreateRealUserDto, userId: string) {
|
||||||
|
const user = await this.userRepository.findOneBy({ id: userId });
|
||||||
|
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||||
|
|
||||||
// async createRealUserData(createDto: CreateRealUserDto, userId: string) {
|
if (user.financialType && user.financialType === FinancialType.LEGAL)
|
||||||
// const userExist = await this.userRepository.findOneBy({
|
throw new BadRequestException(UserMessage.FINANCIAL_TYPE_IS_LEGAL);
|
||||||
// id: userId,
|
//
|
||||||
// });
|
const existRealUser = await this.realUserRepository.findOne({ where: { user: { id: user.id } } });
|
||||||
// if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
|
||||||
// console.log(userExist);
|
|
||||||
// const existingRealUser = await this.realUserRepository.findOne({
|
|
||||||
// where: { user: { id: userExist.id } },
|
|
||||||
// });
|
|
||||||
// console.log(existingRealUser);
|
|
||||||
|
|
||||||
// if (existingRealUser) throw new BadRequestException(RealUserMessage.REAL_DATA_EXIST);
|
if (existRealUser) throw new BadRequestException(UserMessage.REAL_DATA_EXIST);
|
||||||
|
|
||||||
// const { city } = await this.addressService.getCity(+createDto.cityId);
|
const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||||
|
|
||||||
// const realUser = this.realUserRepository.create({
|
const existNationalCode = await this.realUserRepository.findOne({ where: { nationalCode: createDto.nationalCode } });
|
||||||
// ...createDto,
|
if (existNationalCode) throw new BadRequestException(UserMessage.NATIONAL_CODE_EXIST);
|
||||||
// user: userExist,
|
|
||||||
// address: {
|
|
||||||
// address: createDto.address,
|
|
||||||
// city,
|
|
||||||
// postalCode: createDto.postalCode,
|
|
||||||
// user: userExist,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// await this.realUserRepository.save(realUser);
|
const existPhone = await this.realUserRepository.findOne({ where: { phone: createDto.phone } });
|
||||||
|
if (existPhone) throw new BadRequestException(UserMessage.PHONE_EXIST);
|
||||||
|
|
||||||
// return {
|
const realUser = this.realUserRepository.create({
|
||||||
// message: CommonMessage.CREATED,
|
...createDto,
|
||||||
// realUser,
|
user,
|
||||||
// };
|
address: {
|
||||||
// }
|
fullAddress: createDto.address,
|
||||||
|
city,
|
||||||
|
postalCode: createDto.postalCode,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.realUserRepository.save(realUser);
|
||||||
|
|
||||||
|
user.financialType = FinancialType.REAL;
|
||||||
|
await this.userRepository.save(user);
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: CommonMessage.CREATED,
|
||||||
|
realUser,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// /************************************************************ */
|
// /************************************************************ */
|
||||||
|
|
||||||
// async createLegalUserData(createDto: CreateLegalUserDto, userId: string) {
|
//TODO:query manager
|
||||||
// const userExist = await this.userRepository.findOneBy({
|
async createLegalUserData(createDto: CreateLegalUserDto, userId: string) {
|
||||||
// id: userId,
|
const user = await this.userRepository.findOneBy({ id: userId });
|
||||||
// });
|
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||||
// if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
|
||||||
|
|
||||||
// const existingLegalUser = await this.legalUserRepository.findOne({
|
if (user.financialType && user.financialType === FinancialType.REAL) throw new BadRequestException(UserMessage.FINANCIAL_TYPE_IS_REAL);
|
||||||
// where: { user: { id: userExist.id } },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (existingLegalUser) throw new BadRequestException(LegalUserMessage.LEGAL_DATA_EXIST);
|
const existingLegalUser = await this.legalUserRepository.findOne({ where: { user: { id: user.id } } });
|
||||||
|
|
||||||
// const { city } = await this.addressService.getCity(+createDto.cityId);
|
if (existingLegalUser) throw new BadRequestException(UserMessage.LEGAL_DATA_EXIST);
|
||||||
|
|
||||||
// const legalUser = this.legalUserRepository.create({
|
const existEconomicCode = await this.legalUserRepository.findOne({ where: { economicCode: createDto.economicCode } });
|
||||||
// ...createDto,
|
if (existEconomicCode) throw new BadRequestException(UserMessage.ECONOMIC_CODE_EXIST);
|
||||||
// user: userExist,
|
|
||||||
// address: {
|
|
||||||
// address: createDto.address,
|
|
||||||
// city,
|
|
||||||
// postalCode: createDto.postalCode,
|
|
||||||
// user: userExist,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// await this.legalUserRepository.save(legalUser);
|
const existPhone = await this.legalUserRepository.findOne({ where: { phone: createDto.phone } });
|
||||||
|
if (existPhone) throw new BadRequestException(UserMessage.PHONE_EXIST);
|
||||||
|
|
||||||
// return {
|
const existRegistrationCode = await this.legalUserRepository.findOne({ where: { registrationCode: createDto.registrationCode } });
|
||||||
// message: CommonMessage.CREATED,
|
if (existRegistrationCode) throw new BadRequestException(UserMessage.REGISTRATION_CODE_EXIST);
|
||||||
// legalUser,
|
|
||||||
// };
|
const existNationalIdentity = await this.legalUserRepository.findOne({ where: { nationalIdentity: createDto.nationalIdentity } });
|
||||||
// }
|
if (existNationalIdentity) throw new BadRequestException(UserMessage.NATIONAL_IDENTITY_EXIST);
|
||||||
|
|
||||||
|
const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||||
|
|
||||||
|
const legalUser = this.legalUserRepository.create({
|
||||||
|
...createDto,
|
||||||
|
user,
|
||||||
|
address: {
|
||||||
|
fullAddress: createDto.address,
|
||||||
|
city,
|
||||||
|
postalCode: createDto.postalCode,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.legalUserRepository.save(legalUser);
|
||||||
|
|
||||||
|
user.financialType = FinancialType.LEGAL;
|
||||||
|
await this.userRepository.save(user);
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: CommonMessage.CREATED,
|
||||||
|
legalUser,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************ */
|
/************************************************************ */
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { FastifyReply } from "fastify";
|
|||||||
import { ChangeEmailDto } from "./DTO/change-email.dto";
|
import { ChangeEmailDto } from "./DTO/change-email.dto";
|
||||||
import { CheckValidityDTO } from "./DTO/check-validity.dto";
|
import { CheckValidityDTO } from "./DTO/check-validity.dto";
|
||||||
import { CreateAdminDto } from "./DTO/create-admin.dto";
|
import { CreateAdminDto } from "./DTO/create-admin.dto";
|
||||||
|
import { CreateLegalUserDto } from "./DTO/create-legal-user.dto";
|
||||||
|
import { CreateRealUserDto } from "./DTO/create-real-user.dto";
|
||||||
import { CreateRoleDto } from "./DTO/create-role.dto";
|
import { CreateRoleDto } from "./DTO/create-role.dto";
|
||||||
import { SearchAdminQueryDto } from "./DTO/search-admins-query.dto";
|
import { SearchAdminQueryDto } from "./DTO/search-admins-query.dto";
|
||||||
import { SearchRolesQueryDto } from "./DTO/search-roles.dto";
|
import { SearchRolesQueryDto } from "./DTO/search-roles.dto";
|
||||||
@@ -33,14 +35,21 @@ export class UsersController {
|
|||||||
return this.usersService.getMe(userId);
|
return this.usersService.getMe(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
@ApiOperation({ summary: "Get legal user data" })
|
||||||
@ApiOperation({ summary: "Get user financial info" })
|
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@Get("me/financial-info")
|
@Get("legal")
|
||||||
getFinancialInfo(@UserDec("id") userId: string) {
|
getLegalUserData(@UserDec("id") userId: string) {
|
||||||
return this.usersService.getMyFinancialInfo(userId);
|
return this.usersService.getLegalUserData(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation({ summary: "Get real user data" })
|
||||||
|
@AuthGuards()
|
||||||
|
@Get("real")
|
||||||
|
getRealUserData(@UserDec("id") userId: string) {
|
||||||
|
return this.usersService.getRealUserData(userId);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
@ApiOperation({ summary: "Update user profile" })
|
@ApiOperation({ summary: "Update user profile" })
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@Patch("update-profile")
|
@Patch("update-profile")
|
||||||
@@ -164,22 +173,19 @@ export class UsersController {
|
|||||||
return this.usersService.createRole(createDto);
|
return this.usersService.createRole(createDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
@ApiOperation({ summary: "Create real user data ==> user route" })
|
||||||
// @ApiOperation({ summary: "Create real user data" })
|
@AuthGuards()
|
||||||
// @AuthGuards()
|
@Post("real")
|
||||||
// @HttpCode(HttpStatus.CREATED)
|
createRealUser(@Body() createDto: CreateRealUserDto, @UserDec("id") userId: string) {
|
||||||
// @Post("real-user")
|
return this.usersService.createRealUserData(createDto, userId);
|
||||||
// createRealUser(@Body() createDto: CreateRealUserDto, @UserDec("id") userId: string) {
|
}
|
||||||
// return this.usersService.createRealUserData(createDto, userId);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @ApiOperation({ summary: "Create legal user data" })
|
@ApiOperation({ summary: "Create legal user data ==> user route" })
|
||||||
// @AuthGuards()
|
@AuthGuards()
|
||||||
// @HttpCode(HttpStatus.CREATED)
|
@Post("legal")
|
||||||
// @Post("legal-user")
|
createLegalUser(@Body() createDto: CreateLegalUserDto, @UserDec("id") userId: string) {
|
||||||
// createLegalUser(@Body() createDto: CreateLegalUserDto, @UserDec("id") userId: string) {
|
return this.usersService.createLegalUserData(createDto, userId);
|
||||||
// return this.usersService.createLegalUserData(createDto, userId);
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// @ApiOperation({ summary: "Create customer" })
|
// @ApiOperation({ summary: "Create customer" })
|
||||||
// @AuthGuards()
|
// @AuthGuards()
|
||||||
|
|||||||
Reference in New Issue
Block a user