forked from Yara724/api
fix(workflows): resolve QA blockers and protect case evidence
Fix registrar signing, reviewer re-entry, replacement evidence freshness, owner decision and rating races, multipart objections, vehicle serialization and product reporting. Validate uploaded media with FFmpeg, serve evidence through expiring signed links, and add targeted regressions plus a dry-run repair for prematurely completed visit cases.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
// Dry-run by default. Repairs only the precise historical visit-only state;
|
||||
// never reopens a signed, priced or paid claim.
|
||||
require("dotenv").config();
|
||||
const mongoose = require("mongoose");
|
||||
(async () => {
|
||||
if (!process.env.MONGO_URI) throw new Error("MONGO_URI is required");
|
||||
await mongoose.connect(process.env.MONGO_URI, {
|
||||
tls: process.env.MONGO_TLS === "true",
|
||||
tlsAllowInvalidCertificates:
|
||||
process.env.MONGO_TLS_ALLOW_INVALID_CERTS === "true",
|
||||
});
|
||||
try {
|
||||
const collection = mongoose.connection.collection("claimCases");
|
||||
const filter = {
|
||||
status: "COMPLETED",
|
||||
claimStatus: "NEEDS_REVISION",
|
||||
"history.type": "IN_PERSON_VISIT_REQUESTED",
|
||||
"evaluation.damageExpertReply.submittedAt": null,
|
||||
"evaluation.damageExpertReplyFinal.submittedAt": null,
|
||||
"evaluation.ownerInsurerApproval": null,
|
||||
"evaluation.ownerPricedPartsApproval": null,
|
||||
"evaluation.damageExpertReply.parts.0": { $exists: false },
|
||||
"evaluation.damageExpertReplyFinal.parts.0": { $exists: false },
|
||||
};
|
||||
const matched = await collection.countDocuments(filter);
|
||||
if (!process.argv.includes("--apply")) {
|
||||
console.log(JSON.stringify({ dryRun: true, matched }));
|
||||
return;
|
||||
}
|
||||
const result = await collection.updateMany(filter, {
|
||||
$set: {
|
||||
status: "IN_PERSON_VISIT_PENDING",
|
||||
"workflow.locked": false,
|
||||
"workflow.currentStep": "EXPERT_DAMAGE_ASSESSMENT",
|
||||
"workflow.nextStep": "EXPERT_DAMAGE_ASSESSMENT",
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
$unset: {
|
||||
"workflow.lockedBy": "",
|
||||
"workflow.lockedAt": "",
|
||||
"workflow.expiredAt": "",
|
||||
"workflow.preLockQueueSnapshot": "",
|
||||
},
|
||||
$push: {
|
||||
history: {
|
||||
type: "VISIT_ONLY_COMPLETION_REPAIRED",
|
||||
timestamp: new Date(),
|
||||
metadata: { previousStatus: "COMPLETED" },
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
dryRun: false,
|
||||
matched,
|
||||
modified: result.modifiedCount,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
})().catch(() => {
|
||||
console.error(
|
||||
"Visit-state repair failed. Check database connectivity and configuration.",
|
||||
);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user