mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 21:48:18 +00:00
feat(freight-api): add DJF as a supported currency
Adds DJF to freight.payments_currency_enum (migration 3860000000000, alone in its own migration per Postgres's ADD VALUE-in-a-transaction restriction) and to manual_payment_settings (djf_enabled column, migration 3870000000000, default true). Replaces the binary ETB/USD assumptions that would have silently mispriced or discarded a DJF booking: - booking-pricing / contract-pricing: usdToEtb scalar -> a rate table keyed by source currency (ExchangeService.getRateTable), so a contract-frozen rate converts into whatever currency the booking is paid in instead of being dropped when neither leg is ETB or USD. - warehouse-fee / booking-wagon-cancellation: normalizeCurrency no longer coerces anything non-ETB to USD. - additional-charge: convertAmount no longer bails out for a currency that isn't literally ETB or USD. - manual-payment-settings: isEnabled/enabledCurrencies cover DJF. Widens the three @IsIn(['ETB','USD']) DTO validators, and adds DJF to the export/report currency filter option lists. Claude-Session: https://claude.ai/code/session_01CZy77vCWhka3pnmVF9NDkL
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Adds DJF to `freight.payments_currency_enum` — the only currency column in
|
||||
* the schema backed by a real Postgres enum (every other currency column is
|
||||
* a plain varchar and needed no migration).
|
||||
*
|
||||
* This statement must be the ONLY thing in its migration: `ALTER TYPE ... ADD
|
||||
* VALUE` cannot be used within the same transaction that added it (Postgres
|
||||
* restriction, still true on PG 12+), and migrations here run one-per-
|
||||
* transaction (`migrationsTransactionMode: 'each'`). Do not add a seed insert
|
||||
* that writes 'DJF' into `payments.currency` to this file.
|
||||
*/
|
||||
export class AddDjfPaymentsCurrency3860000000000 implements MigrationInterface {
|
||||
name = 'AddDjfPaymentsCurrency3860000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TYPE freight.payments_currency_enum ADD VALUE IF NOT EXISTS 'DJF'`);
|
||||
}
|
||||
|
||||
public async down(): Promise<void> {
|
||||
// Postgres cannot drop a single enum value. Reverting would require
|
||||
// recreating the type and every dependent column/constraint — out of
|
||||
// scope for a currency addition; leave it in place.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* Adds the DJF toggle to `manual_payment_settings`, alongside the existing
|
||||
* `etb_enabled`/`usd_enabled` columns. Defaults to `true` — like USD, DJF
|
||||
* invoices are bank-transfer-settleable from day one.
|
||||
*/
|
||||
export class AddDjfManualPaymentSetting3870000000000 implements MigrationInterface {
|
||||
name = 'AddDjfManualPaymentSetting3870000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.manual_payment_settings
|
||||
ADD COLUMN IF NOT EXISTS djf_enabled boolean NOT NULL DEFAULT true;
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE freight.manual_payment_settings DROP COLUMN IF EXISTS djf_enabled;
|
||||
`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user