forked from Yara724/api
Fixed legacy requestedCounts methods and statistics + claimLink address
This commit is contained in:
@@ -46,64 +46,6 @@ export class DamageExpertDbService {
|
||||
.exec();
|
||||
}
|
||||
|
||||
async updateStats(
|
||||
expertId: string,
|
||||
type: "checked" | "handled",
|
||||
requestId: string,
|
||||
) {
|
||||
if (!expertId || !requestId || !["checked", "handled"].includes(type)) {
|
||||
console.warn("Invalid expertId, requestId, or type");
|
||||
return;
|
||||
}
|
||||
|
||||
const expert = await this.damageExpertModel.findById(expertId);
|
||||
if (!expert) {
|
||||
console.warn("Expert not found:", expertId);
|
||||
return;
|
||||
}
|
||||
|
||||
const requestIdStr = new Types.ObjectId(requestId).toString();
|
||||
const countedRequests =
|
||||
expert.countedRequests?.map((r) => r.toString()) || [];
|
||||
|
||||
if (type === "checked" && countedRequests.includes(requestIdStr)) {
|
||||
console.log(
|
||||
`Request ${requestIdStr} already checked for expert ${expertId}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const update: any = { $inc: {}, $push: {} };
|
||||
|
||||
if (type === "checked") {
|
||||
update.$inc["requestStats.totalChecked"] = 1;
|
||||
update.$push["countedRequests"] = requestIdStr;
|
||||
} else if (type === "handled") {
|
||||
update.$inc["requestStats.totalHandled"] = 1;
|
||||
|
||||
if (countedRequests.includes(requestIdStr)) {
|
||||
update.$inc["requestStats.totalChecked"] = -1;
|
||||
}
|
||||
|
||||
if (!countedRequests.includes(requestIdStr)) {
|
||||
update.$push["countedRequests"] = requestIdStr;
|
||||
} else {
|
||||
delete update.$push;
|
||||
}
|
||||
}
|
||||
|
||||
const result = await this.damageExpertModel.findByIdAndUpdate(
|
||||
expertId,
|
||||
update,
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
console.warn("Failed to update stats for expert:", expertId);
|
||||
} else {
|
||||
console.log(`Stats updated (${type}) for expert:`, expertId);
|
||||
}
|
||||
}
|
||||
|
||||
async updateOne(filter: any, update: any) {
|
||||
return this.damageExpertModel.updateOne(filter, update);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user