fix: bug in thre login process
This commit is contained in:
@@ -1,46 +1,46 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
// import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
// import { IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
// import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class CreateLegalUserDto {
|
||||
@ApiProperty({ description: "Economic code" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
economicCode?: string;
|
||||
// export class CreateLegalUserDto {
|
||||
// @ApiProperty({ description: "Economic code" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
// economicCode?: string;
|
||||
|
||||
@ApiProperty({ description: "Company registered name" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
companyRegisteredName?: string;
|
||||
// @ApiProperty({ description: "Company registered name" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
// companyRegisteredName?: string;
|
||||
|
||||
@ApiProperty({ description: "Registration ID" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.REGISTRATION_ID_INVALID })
|
||||
registrationId?: string;
|
||||
// @ApiProperty({ description: "Registration ID" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.REGISTRATION_ID_INVALID })
|
||||
// registrationId?: string;
|
||||
|
||||
@ApiProperty({ description: "national Id" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
nationalId?: string;
|
||||
// @ApiProperty({ description: "national Id" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
// nationalId?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "number" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.FIXED_PHONE_INVALID })
|
||||
number?: 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: "postalCode" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
// postalCode?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "address" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
address?: 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;
|
||||
}
|
||||
// @ApiPropertyOptional({ description: "City id", example: "1" })
|
||||
// @IsOptional()
|
||||
// @IsNotEmpty({ message: FinancialMessage.CITY_ID_REQUIRED })
|
||||
// cityId: string;
|
||||
// }
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsEnum, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsEnum, IsInt, IsNotEmpty, IsNumberString, IsString } from "class-validator";
|
||||
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
import { GenderType } from "../enums/gender-type.enum";
|
||||
import { GenderEnum } from "../enums/gender-type.enum";
|
||||
import { NationalityEnum } from "../enums/nationality.enum";
|
||||
|
||||
export class CreateRealUserDto {
|
||||
@ApiPropertyOptional({ enum: GenderType, description: "Gender type" })
|
||||
@IsOptional()
|
||||
@IsEnum(GenderType, { message: FinancialMessage.GENDER_TYPE_INVALID })
|
||||
gender?: GenderType;
|
||||
@IsNotEmpty({ message: FinancialMessage.GENDER_TYPE_REQUIRED })
|
||||
@IsEnum(GenderEnum)
|
||||
@ApiProperty({ enum: GenderEnum, description: "Gender type", example: GenderEnum.MALE })
|
||||
gender: GenderEnum;
|
||||
|
||||
@ApiPropertyOptional({ description: "Father name" })
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: FinancialMessage.FATHER_NAME_REQUIRED })
|
||||
@IsString({ message: FinancialMessage.FATHER_NAME_INVALID })
|
||||
fatherName?: string;
|
||||
@ApiProperty({ description: "Father name" })
|
||||
fatherName: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "nationality" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.NATIONALITY_INVALID })
|
||||
nationality?: string;
|
||||
@IsNotEmpty({ message: FinancialMessage.NATIONALITY_REQUIRED })
|
||||
@IsEnum(NationalityEnum)
|
||||
@ApiProperty({ description: "Nationality" })
|
||||
nationality: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "Address" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ADDRESS_ID_INVALID })
|
||||
address?: string;
|
||||
@IsNotEmpty({ message: FinancialMessage.ADDRESS_REQUIRED })
|
||||
@IsString({ message: FinancialMessage.ADDRESS_STRING })
|
||||
@ApiProperty({ description: "Address" })
|
||||
address: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "PostalCode" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ADDRESS_ID_INVALID })
|
||||
postalCode?: string;
|
||||
@IsNotEmpty({ message: FinancialMessage.POSTAL_CODE_REQUIRED })
|
||||
@IsNumberString({ no_symbols: true }, { message: FinancialMessage.POSTAL_CODE_NUMBER_STRING })
|
||||
@ApiProperty({ description: "Postal code", example: "1234567890" })
|
||||
postalCode: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "City id", example: "1" })
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: FinancialMessage.CITY_ID_REQUIRED })
|
||||
cityId: string;
|
||||
@IsInt({ message: FinancialMessage.CITY_ID_INVALID })
|
||||
@ApiProperty({ description: "City ID", example: "1" })
|
||||
cityId: number;
|
||||
}
|
||||
|
||||
@@ -1,92 +1,94 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsEmail, IsMobilePhone, IsNotEmpty, IsNumberString, IsOptional, IsString, IsUrl, Length, MinLength } from "class-validator";
|
||||
// import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
// import { IsEmail, IsMobilePhone, IsNotEmpty, IsNumberString, IsOptional, IsString, IsUrl, Length, MinLength } from "class-validator";
|
||||
|
||||
import { AuthMessage, FinancialMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
// import { IsNationalCode } from "../../../common/decorators/is-national-code.decorator";
|
||||
// import { AuthMessage, FinancialMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class CreateCustomerDto {
|
||||
@IsNotEmpty({ message: AuthMessage.PHONE_NOT_EMPTY })
|
||||
@IsMobilePhone("fa-IR", {}, { message: AuthMessage.INVALID_PHONE_FORMAT })
|
||||
@Length(11, 11, { message: AuthMessage.PHONE_SHOULD_BE_11_DIGIT })
|
||||
@ApiProperty({ description: "phone number", default: "09922320740" })
|
||||
phone: string;
|
||||
// export class CreateCustomerDto {
|
||||
// @IsNotEmpty({ message: AuthMessage.PHONE_NOT_EMPTY })
|
||||
// @IsMobilePhone("fa-IR", {}, { message: AuthMessage.INVALID_PHONE_FORMAT })
|
||||
// @Length(11, 11, { message: AuthMessage.PHONE_SHOULD_BE_11_DIGIT })
|
||||
// @ApiProperty({ description: "phone number", default: "09922320740" })
|
||||
// phone: string;
|
||||
|
||||
@IsNotEmpty({ message: AuthMessage.FIRST_NAME_NOT_EMPTY })
|
||||
@IsString({ message: AuthMessage.FIRST_NAME_NOT_EMPTY })
|
||||
@Length(2, 50, { message: AuthMessage.FIRST_NAME_SHOULD_BE_BETWEEN_2_AND_50 })
|
||||
@ApiProperty({ description: "First name", example: "mahyar" })
|
||||
firstName: string;
|
||||
// @IsNotEmpty({ message: AuthMessage.FIRST_NAME_NOT_EMPTY })
|
||||
// @IsString({ message: AuthMessage.FIRST_NAME_NOT_EMPTY })
|
||||
// @Length(2, 50, { message: AuthMessage.FIRST_NAME_SHOULD_BE_BETWEEN_2_AND_50 })
|
||||
// @ApiProperty({ description: "First name", example: "mahyar" })
|
||||
// firstName: string;
|
||||
|
||||
@IsNotEmpty({ message: AuthMessage.LAST_NAME_NOT_EMPTY })
|
||||
@IsString({ message: AuthMessage.LAST_NAME_NOT_EMPTY })
|
||||
@Length(2, 50, { message: AuthMessage.LAST_NAME_SHOULD_BE_BETWEEN_2_AND_50 })
|
||||
@ApiProperty({ description: "Last name", example: "jamshidi" })
|
||||
lastName: string;
|
||||
// @IsNotEmpty({ message: AuthMessage.LAST_NAME_NOT_EMPTY })
|
||||
// @IsString({ message: AuthMessage.LAST_NAME_NOT_EMPTY })
|
||||
// @Length(2, 50, { message: AuthMessage.LAST_NAME_SHOULD_BE_BETWEEN_2_AND_50 })
|
||||
// @ApiProperty({ description: "Last name", example: "jamshidi" })
|
||||
// lastName: string;
|
||||
|
||||
@IsNotEmpty({ message: AuthMessage.EMAIL_NOT_EMPTY })
|
||||
@IsEmail({}, { message: AuthMessage.INVALID_EMAIL_FORMAT })
|
||||
@ApiProperty({ description: "Email", example: "ma@gmail.com" })
|
||||
email: string;
|
||||
// @IsNotEmpty({ message: AuthMessage.EMAIL_NOT_EMPTY })
|
||||
// @IsEmail({}, { message: AuthMessage.INVALID_EMAIL_FORMAT })
|
||||
// @ApiProperty({ description: "Email", example: "ma@gmail.com" })
|
||||
// email: string;
|
||||
|
||||
@IsNotEmpty({ message: AuthMessage.BIRTH_DATE_NOT_EMPTY })
|
||||
@IsString({ message: AuthMessage.BIRTH_DATE_NOT_EMPTY })
|
||||
@ApiProperty({ description: "Birth date", example: "1403/01/01" })
|
||||
birthDate: string;
|
||||
// @IsNotEmpty({ message: AuthMessage.BIRTH_DATE_NOT_EMPTY })
|
||||
// @IsString({ message: AuthMessage.BIRTH_DATE_NOT_EMPTY })
|
||||
// @ApiProperty({ description: "Birth date", example: "1403/01/01" })
|
||||
// birthDate: string;
|
||||
|
||||
@IsNotEmpty({ message: AuthMessage.NATIONAL_NOT_EMPTY })
|
||||
@IsNumberString({ no_symbols: true }, { message: AuthMessage.NATIONAL_CODE_INCORRECT })
|
||||
@Length(10, 10, { message: AuthMessage.NATIONAL_CODE_INCORRECT })
|
||||
@ApiProperty({ description: "iranian format (10 char)", example: "4569852169" })
|
||||
nationalCode: string;
|
||||
// @IsNotEmpty({ message: AuthMessage.NATIONAL_NOT_EMPTY })
|
||||
// @IsNumberString({ no_symbols: true }, { message: AuthMessage.NATIONAL_CODE_INCORRECT })
|
||||
// @Length(10, 10, { message: AuthMessage.NATIONAL_CODE_INCORRECT })
|
||||
// @IsNationalCode({ message: AuthMessage.NATIONAL_CODE_INVALID })
|
||||
// @ApiProperty({ description: "iranian format (10 char)", example: "4569852169" })
|
||||
// nationalCode: string;
|
||||
|
||||
@IsNotEmpty({ message: AuthMessage.PASSWORD_NOT_EMPTY })
|
||||
@IsString({ message: AuthMessage.PASSWORD_FORMAT_INVALID })
|
||||
@ApiProperty({ description: "password", example: "12S345SS678" })
|
||||
@MinLength(8, { message: AuthMessage.PASSWORD_LENGTH })
|
||||
password: string;
|
||||
// @IsNotEmpty({ message: AuthMessage.PASSWORD_NOT_EMPTY })
|
||||
// @IsString({ message: AuthMessage.PASSWORD_FORMAT_INVALID })
|
||||
// @ApiProperty({ description: "password", example: "12S345SS678" })
|
||||
// @MinLength(8, { message: AuthMessage.PASSWORD_LENGTH })
|
||||
// password: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "Economic code" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
economicCode?: string;
|
||||
// @ApiPropertyOptional({ description: "Economic code" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
// economicCode?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "Company registered name" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
companyRegisteredName?: string;
|
||||
// @ApiPropertyOptional({ description: "Company registered name" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.ECONOMIC_CODE_INVALID })
|
||||
// companyRegisteredName?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "Registration ID" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.REGISTRATION_ID_INVALID })
|
||||
registrationId?: string;
|
||||
// @ApiPropertyOptional({ description: "Registration ID" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.REGISTRATION_ID_INVALID })
|
||||
// registrationId?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "national Id" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
nationalId?: string;
|
||||
// @ApiPropertyOptional({ description: "national Id" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
// nationalId?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "number" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.FIXED_PHONE_INVALID })
|
||||
number?: 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: "postalCode" })
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
// postalCode?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: "address" })
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.NATIONAL_ID_INVALID })
|
||||
address?: 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;
|
||||
// @ApiPropertyOptional({ description: "City id", example: "1" })
|
||||
// @IsOptional()
|
||||
// @IsNotEmpty({ message: FinancialMessage.CITY_ID_REQUIRED })
|
||||
// cityId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: UserMessage.PROFILE_PIC_REQUIRED })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: UserMessage.PROFILE_PIC_URL })
|
||||
@ApiPropertyOptional({ description: "Profile picture", example: "https://www.google.com" })
|
||||
profilePic: string;
|
||||
}
|
||||
// @IsOptional()
|
||||
// @IsNotEmpty({ message: UserMessage.PROFILE_PIC_REQUIRED })
|
||||
// @IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: UserMessage.PROFILE_PIC_URL })
|
||||
// @ApiPropertyOptional({ description: "Profile picture", example: "https://www.google.com" })
|
||||
// profilePic: string;
|
||||
// }
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
// import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
// import { IsOptional, IsString } from "class-validator";
|
||||
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
// import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
// import { FinancialMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class SearchCustomersDto extends PaginationDto {
|
||||
@IsOptional()
|
||||
@IsString({ message: FinancialMessage.SEARCH_QUERY_MUST_BE_A_STRING })
|
||||
@ApiPropertyOptional({ description: "search query", example: "search query" })
|
||||
q: string;
|
||||
}
|
||||
// export class SearchCustomersDto extends PaginationDto {
|
||||
// @IsOptional()
|
||||
// @IsString({ message: FinancialMessage.SEARCH_QUERY_MUST_BE_A_STRING })
|
||||
// @ApiPropertyOptional({ description: "search query", example: "search query" })
|
||||
// q: string;
|
||||
// }
|
||||
|
||||
@@ -3,29 +3,41 @@ import { Column, Entity, JoinColumn, OneToOne, Unique } from "typeorm";
|
||||
import { User } from "./user.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { Address } from "../../address/entities/address.entity";
|
||||
import { GenderType } from "../enums/gender-type.enum";
|
||||
import { GenderEnum } from "../enums/gender-type.enum";
|
||||
import { NationalityEnum } from "../enums/nationality.enum";
|
||||
|
||||
@Unique(["user"])
|
||||
@Entity()
|
||||
export class RealUser extends BaseEntity {
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: GenderType,
|
||||
nullable: true,
|
||||
})
|
||||
gender: GenderType;
|
||||
@Column({ type: "varchar", length: 150 })
|
||||
firstName: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@Column({ type: "varchar", length: 200 })
|
||||
lastName: string;
|
||||
|
||||
@Column({ type: "varchar", length: 100 })
|
||||
fatherName: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
nationality: string;
|
||||
@Column({ type: "varchar", length: 12, nullable: true })
|
||||
birthDate: string;
|
||||
|
||||
@Column({ type: "varchar", length: 100, unique: true })
|
||||
nationalCode: string;
|
||||
|
||||
@Column({ type: "varchar", length: 11, unique: true, nullable: false })
|
||||
phone: string;
|
||||
|
||||
@Column({ type: "enum", enum: GenderEnum })
|
||||
gender: GenderEnum;
|
||||
|
||||
@Column({ type: "enum", enum: NationalityEnum })
|
||||
nationality: NationalityEnum;
|
||||
|
||||
@OneToOne(() => Address, { nullable: false, cascade: true })
|
||||
@JoinColumn()
|
||||
address: Address;
|
||||
|
||||
@OneToOne(() => User, (user) => user.realUser, { onDelete: "CASCADE" })
|
||||
@OneToOne(() => User, (user) => user.realUser, { onDelete: "CASCADE", nullable: false })
|
||||
@JoinColumn()
|
||||
user: User;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { Exclude } from "class-transformer";
|
||||
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, OneToOne } from "typeorm";
|
||||
import { Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne } from "typeorm";
|
||||
|
||||
import { LegalUser } from "./legal-user.entity";
|
||||
import { RealUser } from "./real-user.entity";
|
||||
import { Role } from "./role.entity";
|
||||
import { UserGroup } from "./user-group.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { Address } from "../../address/entities/address.entity";
|
||||
import { City } from "../../address/entities/city.entity";
|
||||
import { UserAnnouncement } from "../../announcements/entities/user-announcement.entity";
|
||||
import { Criticism } from "../../criticisms/entities/criticism.entity";
|
||||
import { DanakServiceReview } from "../../danak-services/entities/danak-service-review.entity";
|
||||
@@ -57,17 +55,8 @@ export class User extends BaseEntity {
|
||||
@Column({ type: "boolean", default: false })
|
||||
emailVerified: boolean;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
userAddress: string;
|
||||
|
||||
@Column({ type: "varchar", length: 10, nullable: true })
|
||||
postalCode: string;
|
||||
//-----------------------------------------
|
||||
|
||||
@ManyToOne(() => City, { eager: true, nullable: true })
|
||||
city: City;
|
||||
// @ManyToOne(() => Role, { eager: true, onDelete: "RESTRICT", nullable: false })
|
||||
// role: Role;
|
||||
@ManyToMany(() => Role, (role) => role.users)
|
||||
@JoinTable({ name: "user_role_relation" })
|
||||
roles: Role[];
|
||||
@@ -119,10 +108,6 @@ export class User extends BaseEntity {
|
||||
@OneToOne(() => LegalUser, (legalUser) => legalUser.user, { cascade: true, nullable: true })
|
||||
legalUser: LegalUser;
|
||||
|
||||
@OneToOne(() => Address, (address) => address.user, { cascade: true, nullable: true })
|
||||
@JoinColumn()
|
||||
address: Address;
|
||||
|
||||
@ManyToMany(() => UsageDiscount, (usageDiscount) => usageDiscount.users)
|
||||
usageDiscounts: UsageDiscount[];
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export enum GenderType {
|
||||
MALE = "male",
|
||||
FEMALE = "female",
|
||||
export enum GenderEnum {
|
||||
MALE = "MALE",
|
||||
FEMALE = "FEMALE",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum NationalityEnum {
|
||||
IRANIAN = "IRANIAN",
|
||||
FOREIGN = "FOREIGN",
|
||||
}
|
||||
@@ -6,15 +6,7 @@ import { FastifyReply } from "fastify";
|
||||
import slugify from "slugify";
|
||||
import { In, Not, QueryRunner } from "typeorm";
|
||||
|
||||
import {
|
||||
AdminMessage,
|
||||
AdsMessage,
|
||||
AuthMessage,
|
||||
CommonMessage,
|
||||
LegalUserMessage,
|
||||
RealUserMessage,
|
||||
UserMessage,
|
||||
} from "../../../common/enums/message.enum";
|
||||
import { AdminMessage, AdsMessage, AuthMessage, CommonMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { AddressService } from "../../address/providers/address.service";
|
||||
import { CompleteRegistrationDto } from "../../auth/DTO/complete-register.dto";
|
||||
import { RequestOtpDto } from "../../auth/DTO/request-otp.dto";
|
||||
@@ -30,12 +22,8 @@ import { WalletsService } from "../../wallets/providers/wallets.service";
|
||||
import { ChangeEmailDto } from "../DTO/change-email.dto";
|
||||
import { CheckValidityDTO } from "../DTO/check-validity.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 { CreateCustomerDto } from "../DTO/create-user.dto";
|
||||
import { SearchAdminQueryDto } from "../DTO/search-admins-query.dto";
|
||||
import { SearchCustomersDto } from "../DTO/search-customers.dto";
|
||||
import { SearchRolesQueryDto } from "../DTO/search-roles.dto";
|
||||
import { UpdateProfileDto } from "../DTO/update-profile.dto";
|
||||
import { CreateUserGroupDto } from "../DTO/user-group.dto";
|
||||
@@ -44,9 +32,7 @@ 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 { LegalUserRepository } from "../repositories/legal-user.repository";
|
||||
import { PermissionsRepository } from "../repositories/permissions.repository";
|
||||
import { RealUserRepository } from "../repositories/real-user.repository";
|
||||
import { RoleRepository } from "../repositories/roles.repository";
|
||||
import { UserGroupRepository } from "../repositories/user-group.repository";
|
||||
import { UserRepository } from "../repositories/users.repository";
|
||||
@@ -62,8 +48,6 @@ export class UsersService {
|
||||
private readonly rolesRepository: RoleRepository,
|
||||
private readonly permissionsRepository: PermissionsRepository,
|
||||
private readonly passwordService: PasswordService,
|
||||
private readonly realUserRepository: RealUserRepository,
|
||||
private readonly legalUserRepository: LegalUserRepository,
|
||||
private readonly addressService: AddressService,
|
||||
private readonly emailService: EmailService,
|
||||
private readonly configService: ConfigService,
|
||||
@@ -90,7 +74,7 @@ export class UsersService {
|
||||
/************************************************************ */
|
||||
|
||||
async getMe(userId: string) {
|
||||
const user = await this.userRepository.findOne({ where: { id: userId }, relations: { roles: true, city: { province: true } } });
|
||||
const user = await this.userRepository.findOne({ where: { id: userId }, relations: { roles: true } });
|
||||
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
return { user };
|
||||
}
|
||||
@@ -405,93 +389,93 @@ export class UsersService {
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async findAllCustomers(queryDto: SearchCustomersDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
// async findAllCustomers(queryDto: SearchCustomersDto) {
|
||||
// const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const queryBuilder = this.userRepository
|
||||
.createQueryBuilder("user")
|
||||
.leftJoin("user.roles", "role")
|
||||
.where("role.name = :roleName", { roleName: RoleEnum.USER })
|
||||
.leftJoin("user.groups", "groups")
|
||||
.addSelect(["groups.id", "groups.name"])
|
||||
.loadRelationCountAndMap("user.invoicesCount", "user.invoices")
|
||||
.loadRelationCountAndMap("user.subscriptionsCount", "user.subscriptions")
|
||||
.loadRelationCountAndMap("user.ticketsCount", "user.tickets");
|
||||
// const queryBuilder = this.userRepository
|
||||
// .createQueryBuilder("user")
|
||||
// .leftJoin("user.roles", "role")
|
||||
// .where("role.name = :roleName", { roleName: RoleEnum.USER })
|
||||
// .leftJoin("user.groups", "groups")
|
||||
// .addSelect(["groups.id", "groups.name"])
|
||||
// .loadRelationCountAndMap("user.invoicesCount", "user.invoices")
|
||||
// .loadRelationCountAndMap("user.subscriptionsCount", "user.subscriptions")
|
||||
// .loadRelationCountAndMap("user.ticketsCount", "user.tickets");
|
||||
|
||||
if (queryDto.q) {
|
||||
queryBuilder
|
||||
.orWhere("user.firstName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.lastName ILIKE :search", { search: `%${queryDto.q}%` })
|
||||
.orWhere("user.userName ILIKE :search", { search: `%${queryDto.q}%` });
|
||||
}
|
||||
// if (queryDto.q) {
|
||||
// queryBuilder
|
||||
// .orWhere("user.firstName 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();
|
||||
// const [customers, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
return { customers, count };
|
||||
}
|
||||
// return { customers, count };
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
async createCustomer(createDto: CreateCustomerDto) {
|
||||
const { cityId, address, postalCode, economicCode, companyRegisteredName, registrationId, nationalId, number, ...userData } = createDto;
|
||||
// async createCustomer(createDto: CreateCustomerDto) {
|
||||
// const { cityId, address, postalCode, economicCode, companyRegisteredName, registrationId, nationalId, number, ...userData } = createDto;
|
||||
|
||||
const queryRunner = this.userRepository.manager.connection.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
// const queryRunner = this.userRepository.manager.connection.createQueryRunner();
|
||||
// await queryRunner.connect();
|
||||
// await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
const existUser = await queryRunner.manager.findOneBy(User, { email: createDto.email });
|
||||
if (existUser) throw new BadRequestException(UserMessage.EMAIL_EXIST);
|
||||
// try {
|
||||
// const existUser = await queryRunner.manager.findOneBy(User, { email: createDto.email });
|
||||
// if (existUser) throw new BadRequestException(UserMessage.EMAIL_EXIST);
|
||||
|
||||
const role = await queryRunner.manager.findOneBy(Role, { name: RoleEnum.USER });
|
||||
if (!role) throw new BadRequestException(UserMessage.ROLE_NOT_FOUND);
|
||||
// const role = await queryRunner.manager.findOneBy(Role, { name: RoleEnum.USER });
|
||||
// if (!role) throw new BadRequestException(UserMessage.ROLE_NOT_FOUND);
|
||||
|
||||
const hashedPassword = await this.passwordService.hashPassword(createDto.password);
|
||||
// const hashedPassword = await this.passwordService.hashPassword(createDto.password);
|
||||
|
||||
const legalUserData = economicCode
|
||||
? {
|
||||
economicCode,
|
||||
companyRegisteredName,
|
||||
registrationId,
|
||||
nationalId,
|
||||
number,
|
||||
address: {
|
||||
address,
|
||||
city: cityId
|
||||
? {
|
||||
id: +cityId,
|
||||
}
|
||||
: undefined,
|
||||
postalCode,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
// const legalUserData = economicCode
|
||||
// ? {
|
||||
// economicCode,
|
||||
// companyRegisteredName,
|
||||
// registrationId,
|
||||
// nationalId,
|
||||
// number,
|
||||
// address: {
|
||||
// address,
|
||||
// city: cityId
|
||||
// ? {
|
||||
// id: +cityId,
|
||||
// }
|
||||
// : undefined,
|
||||
// postalCode,
|
||||
// },
|
||||
// }
|
||||
// : undefined;
|
||||
|
||||
const user = queryRunner.manager.create(User, {
|
||||
...userData,
|
||||
password: hashedPassword,
|
||||
roles: [role],
|
||||
legalUser: legalUserData,
|
||||
});
|
||||
await queryRunner.manager.save(user);
|
||||
// const user = queryRunner.manager.create(User, {
|
||||
// ...userData,
|
||||
// password: hashedPassword,
|
||||
// roles: [role],
|
||||
// legalUser: legalUserData,
|
||||
// });
|
||||
// await queryRunner.manager.save(user);
|
||||
|
||||
await this.userSettingsService.createUserSettings(user.id, queryRunner);
|
||||
// await this.userSettingsService.createUserSettings(user.id, queryRunner);
|
||||
|
||||
await this.walletsService.createUserWallet(user.id, queryRunner);
|
||||
// await this.walletsService.createUserWallet(user.id, queryRunner);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
// await queryRunner.commitTransaction();
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
user,
|
||||
};
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
// return {
|
||||
// message: CommonMessage.CREATED,
|
||||
// user,
|
||||
// };
|
||||
// } catch (error) {
|
||||
// await queryRunner.rollbackTransaction();
|
||||
// throw error;
|
||||
// } finally {
|
||||
// await queryRunner.release();
|
||||
// }
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
@@ -581,74 +565,74 @@ export class UsersService {
|
||||
}
|
||||
/************************************************************ */
|
||||
|
||||
async createRealUserData(createDto: CreateRealUserDto, userId: string) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: userId,
|
||||
});
|
||||
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);
|
||||
// async createRealUserData(createDto: CreateRealUserDto, userId: string) {
|
||||
// const userExist = await this.userRepository.findOneBy({
|
||||
// id: userId,
|
||||
// });
|
||||
// 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 (existingRealUser) throw new BadRequestException(RealUserMessage.REAL_DATA_EXIST);
|
||||
|
||||
const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||
// const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||
|
||||
const realUser = this.realUserRepository.create({
|
||||
...createDto,
|
||||
user: userExist,
|
||||
address: {
|
||||
address: createDto.address,
|
||||
city,
|
||||
postalCode: createDto.postalCode,
|
||||
user: userExist,
|
||||
},
|
||||
});
|
||||
// const realUser = this.realUserRepository.create({
|
||||
// ...createDto,
|
||||
// user: userExist,
|
||||
// address: {
|
||||
// address: createDto.address,
|
||||
// city,
|
||||
// postalCode: createDto.postalCode,
|
||||
// user: userExist,
|
||||
// },
|
||||
// });
|
||||
|
||||
await this.realUserRepository.save(realUser);
|
||||
// await this.realUserRepository.save(realUser);
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
realUser,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// message: CommonMessage.CREATED,
|
||||
// realUser,
|
||||
// };
|
||||
// }
|
||||
|
||||
// /************************************************************ */
|
||||
|
||||
async createLegalUserData(createDto: CreateLegalUserDto, userId: string) {
|
||||
const userExist = await this.userRepository.findOneBy({
|
||||
id: userId,
|
||||
});
|
||||
if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
// async createLegalUserData(createDto: CreateLegalUserDto, userId: string) {
|
||||
// const userExist = await this.userRepository.findOneBy({
|
||||
// id: userId,
|
||||
// });
|
||||
// if (!userExist) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
|
||||
|
||||
const existingLegalUser = await this.legalUserRepository.findOne({
|
||||
where: { user: { id: userExist.id } },
|
||||
});
|
||||
// const existingLegalUser = await this.legalUserRepository.findOne({
|
||||
// where: { user: { id: userExist.id } },
|
||||
// });
|
||||
|
||||
if (existingLegalUser) throw new BadRequestException(LegalUserMessage.LEGAL_DATA_EXIST);
|
||||
// if (existingLegalUser) throw new BadRequestException(LegalUserMessage.LEGAL_DATA_EXIST);
|
||||
|
||||
const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||
// const { city } = await this.addressService.getCity(+createDto.cityId);
|
||||
|
||||
const legalUser = this.legalUserRepository.create({
|
||||
...createDto,
|
||||
user: userExist,
|
||||
address: {
|
||||
address: createDto.address,
|
||||
city,
|
||||
postalCode: createDto.postalCode,
|
||||
user: userExist,
|
||||
},
|
||||
});
|
||||
// const legalUser = this.legalUserRepository.create({
|
||||
// ...createDto,
|
||||
// user: userExist,
|
||||
// address: {
|
||||
// address: createDto.address,
|
||||
// city,
|
||||
// postalCode: createDto.postalCode,
|
||||
// user: userExist,
|
||||
// },
|
||||
// });
|
||||
|
||||
await this.legalUserRepository.save(legalUser);
|
||||
// await this.legalUserRepository.save(legalUser);
|
||||
|
||||
return {
|
||||
message: CommonMessage.CREATED,
|
||||
legalUser,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// message: CommonMessage.CREATED,
|
||||
// legalUser,
|
||||
// };
|
||||
// }
|
||||
|
||||
/************************************************************ */
|
||||
|
||||
|
||||
@@ -5,12 +5,8 @@ import { FastifyReply } from "fastify";
|
||||
import { ChangeEmailDto } from "./DTO/change-email.dto";
|
||||
import { CheckValidityDTO } from "./DTO/check-validity.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 { CreateCustomerDto } from "./DTO/create-user.dto";
|
||||
import { SearchAdminQueryDto } from "./DTO/search-admins-query.dto";
|
||||
import { SearchCustomersDto } from "./DTO/search-customers.dto";
|
||||
import { SearchRolesQueryDto } from "./DTO/search-roles.dto";
|
||||
import { UpdateProfileDto } from "./DTO/update-profile.dto";
|
||||
import { CreateUserGroupDto } from "./DTO/user-group.dto";
|
||||
@@ -112,13 +108,13 @@ export class UsersController {
|
||||
return this.usersService.findAllUsers();
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "get all customers ==> admin route" })
|
||||
@AuthGuards()
|
||||
@PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)
|
||||
@Get("customers")
|
||||
customers(@Query() queryDto: SearchCustomersDto) {
|
||||
return this.usersService.findAllCustomers(queryDto);
|
||||
}
|
||||
// @ApiOperation({ summary: "get all customers ==> admin route" })
|
||||
// @AuthGuards()
|
||||
// @PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)
|
||||
// @Get("customers")
|
||||
// customers(@Query() queryDto: SearchCustomersDto) {
|
||||
// return this.usersService.findAllCustomers(queryDto);
|
||||
// }
|
||||
|
||||
@ApiOperation({ summary: "get all customers ==> admin route" })
|
||||
@AuthGuards()
|
||||
@@ -169,27 +165,27 @@ export class UsersController {
|
||||
}
|
||||
|
||||
//
|
||||
@ApiOperation({ summary: "Create real user data" })
|
||||
@AuthGuards()
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Post("real-user")
|
||||
createRealUser(@Body() createDto: CreateRealUserDto, @UserDec("id") userId: string) {
|
||||
return this.usersService.createRealUserData(createDto, userId);
|
||||
}
|
||||
// @ApiOperation({ summary: "Create real user data" })
|
||||
// @AuthGuards()
|
||||
// @HttpCode(HttpStatus.CREATED)
|
||||
// @Post("real-user")
|
||||
// createRealUser(@Body() createDto: CreateRealUserDto, @UserDec("id") userId: string) {
|
||||
// return this.usersService.createRealUserData(createDto, userId);
|
||||
// }
|
||||
|
||||
@ApiOperation({ summary: "Create legal user data" })
|
||||
@AuthGuards()
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Post("legal-user")
|
||||
createLegalUser(@Body() createDto: CreateLegalUserDto, @UserDec("id") userId: string) {
|
||||
return this.usersService.createLegalUserData(createDto, userId);
|
||||
}
|
||||
// @ApiOperation({ summary: "Create legal user data" })
|
||||
// @AuthGuards()
|
||||
// @HttpCode(HttpStatus.CREATED)
|
||||
// @Post("legal-user")
|
||||
// createLegalUser(@Body() createDto: CreateLegalUserDto, @UserDec("id") userId: string) {
|
||||
// return this.usersService.createLegalUserData(createDto, userId);
|
||||
// }
|
||||
|
||||
@ApiOperation({ summary: "Create customer" })
|
||||
@AuthGuards()
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Post("customer")
|
||||
createCustomer(@Body() createDto: CreateCustomerDto) {
|
||||
return this.usersService.createCustomer(createDto);
|
||||
}
|
||||
// @ApiOperation({ summary: "Create customer" })
|
||||
// @AuthGuards()
|
||||
// @HttpCode(HttpStatus.CREATED)
|
||||
// @Post("customer")
|
||||
// createCustomer(@Body() createDto: CreateCustomerDto) {
|
||||
// return this.usersService.createCustomer(createDto);
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user