mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
/**
|
||
* One-off data fix: corrects PaymentMethod.currency for methods whose settlement currency
|
||
* was never set at seed time and silently defaulted to the schema's ETB default.
|
||
*
|
||
* payments.service.ts's chargeCurrency resolution reads this column directly (see the
|
||
* comment above `chargeCurrency` in `initiatePayment`): WAAFI settles in DJF, CARD in USD.
|
||
* With WAAFI stuck on the ETB default, live Waafi payments were charged in ETB instead of
|
||
* being converted to DJF — not just a mislabeled report. This script only touches the
|
||
* PaymentMethod config row; it does NOT rewrite any existing PaymentIntent/Booking records,
|
||
* since correcting historical transaction currency is a financial decision, not a data-fix
|
||
* this script should make unilaterally.
|
||
*
|
||
* Safe to re-run. Only updates rows that already exist; does not create new ones.
|
||
*
|
||
* Usage: node --env-file=.env -r ts-node/register prisma/fix-payment-method-currency.ts
|
||
*/
|
||
import { PrismaClient } from '@prisma/client';
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
const CORRECTIONS: { type: string; currency: string }[] = [
|
||
{ type: 'WAAFI', currency: 'DJF' },
|
||
{ type: 'CARD', currency: 'USD' },
|
||
];
|
||
|
||
async function main() {
|
||
for (const { type, currency } of CORRECTIONS) {
|
||
const existing = await prisma.paymentMethod.findUnique({ where: { type: type as any } });
|
||
if (!existing) {
|
||
console.log(` ⚠️ No PaymentMethod row for ${type} — skipping (nothing to correct).`);
|
||
continue;
|
||
}
|
||
if (existing.currency === currency) {
|
||
console.log(` ℹ️ ${type} already set to ${currency} — no change.`);
|
||
continue;
|
||
}
|
||
await prisma.paymentMethod.update({ where: { type: type as any }, data: { currency } });
|
||
console.log(` ✅ ${type}: ${existing.currency} → ${currency}`);
|
||
}
|
||
}
|
||
|
||
main()
|
||
.catch((e) => {
|
||
console.error('❌ fix-payment-method-currency failed:', e);
|
||
process.exitCode = 1;
|
||
})
|
||
.finally(async () => {
|
||
await prisma.$disconnect();
|
||
});
|