Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,81 @@ export const softwareUpdates = pgTable(

export type SoftwareUpdate = typeof softwareUpdates.$inferSelect;

// ─── Terminal Leases ───────────────────────────────────────────────────────────
export const terminalLeases = pgTable(
"terminal_leases",
{
id: serial("id").primaryKey(),
terminalId: integer("terminalId")
.references(() => posTerminals.id)
.notNull(),
agentId: integer("agentId")
.references(() => agents.id)
.notNull(),
leaseType: varchar("leaseType", { length: 32 })
.notNull()
.default("standard"),
monthlyRate: integer("monthlyRate").notNull(),
depositAmount: integer("depositAmount").default(0).notNull(),
insuranceRate: integer("insuranceRate").default(0).notNull(),
startDate: timestamp("startDate").notNull(),
endDate: timestamp("endDate").notNull(),
status: varchar("status", { length: 32 }).notNull().default("active"),
paymentDay: integer("paymentDay").default(1).notNull(),
totalPaid: integer("totalPaid").default(0).notNull(),
missedPayments: integer("missedPayments").default(0).notNull(),
lastPaymentAt: timestamp("lastPaymentAt"),
nextPaymentDue: timestamp("nextPaymentDue"),
returnCondition: varchar("returnCondition", { length: 32 }),
returnedAt: timestamp("returnedAt"),
notes: text("notes"),
tenantId: integer("tenantId"),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().notNull(),
},
t => ({
tl_terminalId_idx: index("tl_terminalId_idx").on(t.terminalId),
tl_agentId_idx: index("tl_agentId_idx").on(t.agentId),
tl_status_idx: index("tl_status_idx").on(t.status),
tl_nextPayment_idx: index("tl_nextPayment_idx").on(t.nextPaymentDue),
})
);

export type TerminalLease = typeof terminalLeases.$inferSelect;

// ─── POS Settlement Batches ────────────────────────────────────────────────────
export const posSettlementBatches = pgTable(
"pos_settlement_batches",
{
id: serial("id").primaryKey(),
batchRef: varchar("batchRef", { length: 64 }).notNull().unique(),
terminalId: integer("terminalId").references(() => posTerminals.id),
agentId: integer("agentId").references(() => agents.id),
transactionCount: integer("transactionCount").notNull().default(0),
totalAmount: integer("totalAmount").notNull().default(0),
totalFees: integer("totalFees").notNull().default(0),
netAmount: integer("netAmount").notNull().default(0),
currency: varchar("currency", { length: 3 }).default("NGN").notNull(),
status: varchar("status", { length: 32 }).notNull().default("pending"),
settledAt: timestamp("settledAt"),
settlementRef: varchar("settlementRef", { length: 128 }),
periodStart: timestamp("periodStart").notNull(),
periodEnd: timestamp("periodEnd").notNull(),
tenantId: integer("tenantId"),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().notNull(),
},
t => ({
psb_batchRef_idx: uniqueIndex("psb_batchRef_idx").on(t.batchRef),
psb_terminalId_idx: index("psb_terminalId_idx").on(t.terminalId),
psb_agentId_idx: index("psb_agentId_idx").on(t.agentId),
psb_status_idx: index("psb_status_idx").on(t.status),
psb_period_idx: index("psb_period_idx").on(t.periodStart, t.periodEnd),
})
);

export type PosSettlementBatch = typeof posSettlementBatches.$inferSelect;

// ─── Commission Rules ─────────────────────────────────────────────────────────
export const commissionRules = pgTable(
"commission_rules",
Expand Down Expand Up @@ -5139,3 +5214,65 @@ export const deliveryTracking = pgTable(
})
);
export type DeliveryTrackingRecord = typeof deliveryTracking.$inferSelect;

// ─── AML Screening Tables ───────────────────────────────────────────────────
export const amlScreenings = pgTable(
"aml_screenings",
{
id: serial("id").primaryKey(),
entityName: varchar("entity_name", { length: 200 }).notNull(),
entityType: varchar("entity_type", { length: 20 }).notNull(),
country: varchar("country", { length: 2 }),
nationalId: varchar("national_id", { length: 50 }),
riskScore: integer("risk_score").notNull().default(0),
status: varchar("status", { length: 20 }).notNull().default("clear"),
sanctionsMatch: boolean("sanctions_match").notNull().default(false),
pepMatch: boolean("pep_match").notNull().default(false),
adverseMediaMatch: boolean("adverse_media_match").notNull().default(false),
highRiskCountry: boolean("high_risk_country").notNull().default(false),
screenedAt: timestamp("screened_at").defaultNow().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
},
t => ({
statusIdx: index("aml_status_idx").on(t.status),
entityIdx: index("aml_entity_idx").on(t.entityName),
riskIdx: index("aml_risk_idx").on(t.riskScore),
})
);

export const amlWatchlistEntries = pgTable(
"aml_watchlist_entries",
{
id: serial("id").primaryKey(),
entityName: varchar("entity_name", { length: 200 }).notNull(),
aliases: text("aliases"),
listType: varchar("list_type", { length: 30 }).notNull(),
sourceList: varchar("source_list", { length: 100 }),
country: varchar("country", { length: 2 }),
dateAdded: timestamp("date_added").defaultNow().notNull(),
active: boolean("active").notNull().default(true),
},
t => ({
nameIdx: index("awl_name_idx").on(t.entityName),
listIdx: index("awl_list_idx").on(t.listType),
})
);

// ─── Idempotency Keys Table ────────────────────────────────────────────────
export const idempotencyKeys = pgTable(
"idempotency_keys",
{
id: serial("id").primaryKey(),
idempotencyKey: varchar("idempotency_key", { length: 128 })
.notNull()
.unique(),
responseData: text("response_data"),
createdAt: timestamp("created_at").defaultNow().notNull(),
expiresAt: timestamp("expires_at").notNull(),
},
t => ({
keyIdx: uniqueIndex("idem_key_idx").on(t.idempotencyKey),
expiryIdx: index("idem_expiry_idx").on(t.expiresAt),
})
);
2 changes: 2 additions & 0 deletions server/routers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ import { dynamicPricingEngineRouter } from "./routers/dynamicPricingEngine";
import { customerLoyaltyProgramRouter } from "./routers/customerLoyaltyProgram";
import { fraudCaseManagementRouter } from "./routers/fraudCaseManagement";
import { posTerminalFleetRouter } from "./routers/posTerminalFleet";
import { posBatchSettlementRouter } from "./routers/posBatchSettlement";
import { financialReconciliationDashRouter } from "./routers/financialReconciliationDash";
import { apiAnalyticsDashRouter } from "./routers/apiAnalyticsDash";
import { agentCommunicationHubRouter } from "./routers/agentCommunicationHub";
Expand Down Expand Up @@ -796,6 +797,7 @@ export const appRouter = router({
customerLoyaltyProgram: customerLoyaltyProgramRouter,
fraudCaseManagement: fraudCaseManagementRouter,
posTerminalFleet: posTerminalFleetRouter,
posBatchSettlement: posBatchSettlementRouter,
financialReconciliationDash: financialReconciliationDashRouter,
apiAnalyticsDash: apiAnalyticsDashRouter,
agentCommunicationHub: agentCommunicationHubRouter,
Expand Down
Loading
Loading