Added in-person expert

This commit is contained in:
SepehrYahyaee
2026-02-24 12:16:14 +03:30
parent 0d8858f458
commit 64b6101177
13 changed files with 512 additions and 22 deletions

View File

@@ -0,0 +1,49 @@
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { FilterQuery, Model, Types } from "mongoose";
import { FieldExpertModel } from "../schema/field-expert.schema";
@Injectable()
export class FieldExpertDbService {
constructor(
@InjectModel(FieldExpertModel.name)
private readonly fieldExpertModel: Model<FieldExpertModel>,
) {}
async create(
user: Partial<FieldExpertModel> & { password: string },
): Promise<FieldExpertModel> {
return await this.fieldExpertModel.create(user);
}
async findOne(
filter: FilterQuery<FieldExpertModel>,
): Promise<FieldExpertModel | null> {
return await this.fieldExpertModel.findOne(filter);
}
async findById(userId: string): Promise<FieldExpertModel | null> {
return await this.fieldExpertModel.findOne({
_id: new Types.ObjectId(userId),
});
}
async findOneAndUpdate(
filter: FilterQuery<FieldExpertModel>,
update: FilterQuery<FieldExpertModel>,
) {
return await this.fieldExpertModel.findOneAndUpdate(filter, update, {
new: true,
});
}
async findAll(
filter: FilterQuery<FieldExpertModel>,
): Promise<(FieldExpertModel & { _id: Types.ObjectId })[]> {
return await this.fieldExpertModel.find(filter).lean();
}
async updateOne(filter: FilterQuery<FieldExpertModel>, update: any) {
return this.fieldExpertModel.updateOne(filter, update);
}
}

View File

@@ -0,0 +1,78 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Types } from "mongoose";
import { RoleEnum } from "src/Types&Enums/role.enum";
@Schema({ _id: false })
export class RequestStats {
@Prop({ default: 0 })
totalHandled: number;
@Prop({ default: 0 })
totalChecked: number;
}
const RequestStatsSchema = SchemaFactory.createForClass(RequestStats);
@Schema({
collection: "field-expert",
versionKey: false,
timestamps: true,
})
export class FieldExpertModel {
_id?: Types.ObjectId;
@Prop({ required: true })
firstName: string;
@Prop({ required: true })
lastName: 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({ default: RoleEnum.FIELD_EXPERT })
role: RoleEnum;
@Prop({ type: "string", default: "" })
otp: 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 FieldExpertDbSchema =
SchemaFactory.createForClass(FieldExpertModel);
FieldExpertDbSchema.pre("save", function (next) {
if (!this.username) {
this.username = this.email;
}
if (!this.requestStats) {
this.requestStats = { totalChecked: 0, totalHandled: 0 };
}
next();
});