forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
197
src/users/entities/schema/damage-expert.schema.ts
Normal file
197
src/users/entities/schema/damage-expert.schema.ts
Normal file
@@ -0,0 +1,197 @@
|
||||
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 RequestStats {
|
||||
@Prop({ default: 0 })
|
||||
totalHandled: number;
|
||||
|
||||
@Prop({ default: 0 })
|
||||
totalChecked: number;
|
||||
}
|
||||
|
||||
const RequestStatsSchema = SchemaFactory.createForClass(RequestStats);
|
||||
|
||||
@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 })
|
||||
insuActivityCo?: string | null;
|
||||
|
||||
@Prop({ type: Types.ObjectId })
|
||||
clientKey?: 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: RequestStatsSchema, default: () => ({}) })
|
||||
requestStats: RequestStats;
|
||||
|
||||
@Prop({
|
||||
type: [{ type: String }],
|
||||
default: [],
|
||||
validate: {
|
||||
validator: (arr: any[]) => arr.every((val) => typeof val === "string"),
|
||||
message: "All countedRequests must be strings",
|
||||
},
|
||||
})
|
||||
countedRequests?: string[];
|
||||
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export const DamageExpertDbSchema =
|
||||
SchemaFactory.createForClass(DamageExpertModel);
|
||||
|
||||
DamageExpertDbSchema.pre("save", function (next) {
|
||||
if (!this.username) {
|
||||
this.username = this.email;
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
DamageExpertDbSchema.pre("save", function (next) {
|
||||
if (!this.requestStats) {
|
||||
this.requestStats = { totalChecked: 0, totalHandled: 0 };
|
||||
}
|
||||
next();
|
||||
});
|
||||
Reference in New Issue
Block a user