1
0
forked from Yara724/api

Fixed legacy requestedCounts methods and statistics + claimLink address

This commit is contained in:
SepehrYahyaee
2026-04-27 15:29:44 +03:30
parent 362e02ddc4
commit c2f996cc28
17 changed files with 441 additions and 394 deletions

View File

@@ -8,16 +8,6 @@ import {
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 {
@@ -166,19 +156,6 @@ export class DamageExpertModel {
@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;
}
@@ -190,11 +167,4 @@ DamageExpertDbSchema.pre("save", function (next) {
this.username = this.email;
}
next();
});
DamageExpertDbSchema.pre("save", function (next) {
if (!this.requestStats) {
this.requestStats = { totalChecked: 0, totalHandled: 0 };
}
next();
});
});

View File

@@ -0,0 +1,52 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { HydratedDocument, Types } from "mongoose";
export type ExpertFileActivityDocument = HydratedDocument<ExpertFileActivity>;
export enum ExpertFileActivityType {
CHECKED = "checked",
HANDLED = "handled",
UNCHECKED = "unchecked",
}
export enum ExpertFileKind {
BLAME = "blame",
CLAIM = "claim",
}
@Schema({ collection: "expertFileActivities", timestamps: true })
export class ExpertFileActivity {
@Prop({ type: Types.ObjectId, required: true, index: true })
expertId: Types.ObjectId;
@Prop({ type: Types.ObjectId, required: true, index: true })
tenantId: Types.ObjectId;
@Prop({ type: Types.ObjectId, required: true, index: true })
fileId: Types.ObjectId;
@Prop({ type: String, enum: ExpertFileKind, required: true, index: true })
fileType: ExpertFileKind;
@Prop({
type: String,
enum: ExpertFileActivityType,
required: true,
index: true,
})
eventType: ExpertFileActivityType;
@Prop({ type: Date, default: Date.now, index: true })
occurredAt: Date;
@Prop({ type: String, required: false, index: true })
idempotencyKey?: string;
}
export const ExpertFileActivitySchema =
SchemaFactory.createForClass(ExpertFileActivity);
ExpertFileActivitySchema.index(
{ idempotencyKey: 1 },
{ unique: true, partialFilterExpression: { idempotencyKey: { $exists: true } } },
);

View File

@@ -3,17 +3,6 @@ import { Degrees } from "src/Types&Enums/degrees.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({ collection: "expert", versionKey: false, timestamps: true })
export class ExpertModel {
@Prop({})
@@ -79,27 +68,8 @@ export class ExpertModel {
@Prop({ type: "string" })
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 ExpertDbSchema = SchemaFactory.createForClass(ExpertModel);
ExpertDbSchema.pre("save", function (next) {
if (!this.requestStats) {
this.requestStats = { totalChecked: 0, totalHandled: 0 };
}
next();
});

View File

@@ -2,17 +2,6 @@ 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,
@@ -48,31 +37,8 @@ export class FieldExpertModel {
@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();
});
SchemaFactory.createForClass(FieldExpertModel);