import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; import { Types } from "mongoose"; import { ExpertizedAtEnum, PreviousWorkEnum, SkillEnum, } from "src/Types&Enums/damage-expert.enum"; import { RoleEnum } from "src/Types&Enums/role.enum"; import { UserType } from "src/Types&Enums/userType.enum"; @Schema({ _id: false }) export class PersonalInfo { @Prop({ type: "string" }) fullName: string; @Prop({ type: "string" }) nationalCode: string; @Prop({ type: "string" }) dob: string; @Prop({ type: "string" }) mobile: string; } const PersonalInfoSchema = SchemaFactory.createForClass(PersonalInfo); @Schema({ _id: false }) export class PersonalDocs { @Prop({ type: "string" }) nationalCard?: string; @Prop({ type: "string" }) selfie?: string; @Prop({ type: "string" }) activityCert?: string; } const PersonalDocsSchema = SchemaFactory.createForClass(PersonalDocs); @Schema({ _id: false }) export class WorkExperience { @Prop({ type: Number }) state: number; @Prop({ type: Number }) city: number; @Prop({ type: [{ type: String, enum: ExpertizedAtEnum }], default: [], }) expertizedAt: ExpertizedAtEnum[]; } const WorkExperienceSchema = SchemaFactory.createForClass(WorkExperience); @Schema({ _id: false }) export class WorkRecords { @Prop({ type: Number }) workingYears: number; @Prop({ type: Number }) casesCount: number; @Prop({ type: String, enum: PreviousWorkEnum }) previousWork: PreviousWorkEnum; } const WorkRecordsSchema = SchemaFactory.createForClass(WorkRecords); @Schema({ _id: false }) export class FinancialInfo { @Prop({ type: "string" }) IBAN: string; @Prop({ type: "string" }) cardNum: string; @Prop({ type: "string" }) accountNum: string; } const FinancialInfoSchema = SchemaFactory.createForClass(FinancialInfo); @Schema({ collection: "damage-expert", versionKey: false, timestamps: true }) export class DamageExpertModel { @Prop({ required: true }) userType: UserType; @Prop({ required: true }) firstName: string; @Prop({ required: true }) role: RoleEnum; @Prop({ required: true }) lastName: string; @Prop({ unique: true }) nationalCode: string; @Prop({ type: "string", unique: true }) email: string; @Prop({ type: "string" }) username: string; @Prop({ required: true }) password: string; @Prop({ required: true }) mobile: string; @Prop({ required: false }) phone?: string; @Prop({ required: false }) insuActivityCo?: string | null; @Prop({ type: Types.ObjectId }) clientKey?: Types.ObjectId; @Prop({ type: Types.ObjectId, index: true }) branchId?: Types.ObjectId; @Prop({ type: PersonalInfoSchema }) personalInfo?: PersonalInfo; @Prop({ type: PersonalDocsSchema }) personalDocs?: PersonalDocs; @Prop({ type: WorkExperienceSchema }) workExperience?: WorkExperience; @Prop({ type: WorkRecordsSchema }) workRecords?: WorkRecords; @Prop({ type: [{ type: String, enum: SkillEnum }], default: [], }) skills?: SkillEnum[]; @Prop({ type: FinancialInfoSchema }) financialInfo?: FinancialInfo; @Prop({ type: "string" }) otp: string; @Prop({ type: "string" }) address: string; @Prop({ type: "string" }) state: string; @Prop({ type: "string" }) city: string; @Prop({type: "string", required: false}) expertCode?: string; createdAt: Date; } export const DamageExpertDbSchema = SchemaFactory.createForClass(DamageExpertModel); DamageExpertDbSchema.pre("save", function (next) { if (!this.username) { this.username = this.email; } next(); });