forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReconciliationReport.ts
More file actions
72 lines (64 loc) · 2.13 KB
/
Copy pathReconciliationReport.ts
File metadata and controls
72 lines (64 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import mongoose from "mongoose";
export type MismatchType =
| "orphan_on_chain"
| "missing_fulfillment"
| "webhook_undelivered"
| "amount_mismatch";
export type RepairStatus = "pending" | "approved" | "completed" | "failed" | "skipped";
export interface IMismatchItem {
type: MismatchType;
promptId: string;
buyerWallet: string;
txHash?: string;
details?: Record<string, unknown>;
repairStatus: RepairStatus;
repairedAt?: Date;
repairError?: string;
}
const mismatchItemSchema = new mongoose.Schema(
{
type: {
type: String,
enum: ["orphan_on_chain", "missing_fulfillment", "webhook_undelivered", "amount_mismatch"],
required: true,
},
promptId: { type: String, required: true },
buyerWallet: { type: String, required: true, lowercase: true },
txHash: { type: String, default: "" },
details: { type: mongoose.Schema.Types.Mixed },
repairStatus: {
type: String,
enum: ["pending", "approved", "completed", "failed", "skipped"],
default: "pending",
},
repairedAt: { type: Date },
repairError: { type: String },
},
{ _id: false }
);
const reconciliationReportSchema = new mongoose.Schema(
{
reportId: { type: String, required: true, unique: true, index: true },
scannedLedgerStart: { type: Number, default: 0 },
scannedLedgerEnd: { type: Number, default: 0 },
totalOnChainPurchases: { type: Number, default: 0 },
totalDbPurchases: { type: Number, default: 0 },
totalFulfillments: { type: Number, default: 0 },
mismatches: [mismatchItemSchema],
isDryRun: { type: Boolean, default: true },
signature: { type: String, required: true },
createdBy: { type: String, default: "system" },
approvedBy: { type: String, default: null },
status: {
type: String,
enum: ["generated", "partially_repaired", "fully_repaired"],
default: "generated",
},
},
{ timestamps: true }
);
reconciliationReportSchema.index({ createdAt: -1 });
const ReconciliationReport =
mongoose.models.ReconciliationReport ||
mongoose.model("ReconciliationReport", reconciliationReportSchema);
export default ReconciliationReport;