Files
yara724-api/src/users/entities/schema/field-expert.schema.ts
T
SepehrYahyaee 83376df4ad feat: manage expert access and merge Parsian expert seeds
Allow role-specific identities and admin account activation, support national-code-only claim experts, and remove required voice from v4/v5. Add a combined, resumable Parsian seed that preserves existing accounts and merges locations and product codes.
2026-11-18 17:16:26 +03:30

109 lines
2.3 KiB
TypeScript

import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Types } from "mongoose";
import { RoleEnum } from "src/Types&Enums/role.enum";
@Schema({ _id: false, versionKey: false })
export class FieldExpertLocationModel {
@Prop({ type: String, required: true })
id: string;
@Prop({ type: String, required: true })
name: string;
}
export const FieldExpertLocationDbSchema = SchemaFactory.createForClass(
FieldExpertLocationModel,
);
@Schema({
collection: "field-expert",
versionKey: false,
timestamps: true,
})
export class FieldExpertModel {
_id?: Types.ObjectId;
@Prop({ type: Boolean, default: true })
isActive?: boolean;
@Prop({ required: true })
firstName: string;
@Prop({ required: true })
lastName: string;
@Prop({ type: String, unique: true, sparse: true, required: false })
email?: string;
@Prop({ type: String })
username?: string;
@Prop({ type: String, index: true, sparse: true })
nationalCode?: string;
@Prop({ type: Types.ObjectId, index: true })
clientKey?: Types.ObjectId;
@Prop({ type: Types.ObjectId, index: true })
branchId?: Types.ObjectId;
@Prop({ type: [FieldExpertLocationDbSchema], default: [] })
locations?: FieldExpertLocationModel[];
@Prop({ required: true })
password: string;
@Prop({ required: false })
mobile?: string;
@Prop({ required: false })
phone?: string;
@Prop({ type: String })
city?: string;
@Prop({ type: String })
state?: string;
@Prop({ type: String })
address?: string;
@Prop({ default: RoleEnum.FIELD_EXPERT })
role: RoleEnum;
@Prop({ type: "string", default: "" })
otp: string;
@Prop({ type: "string", required: false })
expertCode?: string;
@Prop({ type: String, required: false })
ThirdPartyClaimExpertId?: string;
@Prop({ type: String, required: false })
CarBodyClaimExpertId?: string;
@Prop({ type: String, required: false })
ThirdPartyExpertiseClaim?: string;
@Prop({ type: String, required: false })
CarBodyExpertiseClaim?: string;
createdAt: Date;
}
export const FieldExpertDbSchema =
SchemaFactory.createForClass(FieldExpertModel);
FieldExpertDbSchema.index(
{ clientKey: 1, nationalCode: 1 },
{ unique: true, sparse: true },
);
FieldExpertDbSchema.pre("save", function (next) {
if (!this.username) {
this.username = this.email || this.nationalCode;
}
next();
});