From 83da50eb0d43d2636108a817f7ace671a9f0c7fa Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Mon, 22 Jan 2024 14:40:09 -0800 Subject: [PATCH] feat: Map plaid account --- verticals/vertical-banking/banking.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/verticals/vertical-banking/banking.ts b/verticals/vertical-banking/banking.ts index dce284d7..ae00b1d3 100644 --- a/verticals/vertical-banking/banking.ts +++ b/verticals/vertical-banking/banking.ts @@ -26,6 +26,8 @@ export const zBanking = { account: z.object({ id: z.string(), name: z.string(), + current_balance: z.number().optional(), + currency: z.string().optional(), }), merchant: z.object({ id: z.string(), @@ -134,6 +136,20 @@ export function bankingLink(ctx: { } satisfies PostgresInputPayload, }) } + if (op.data.entityName === 'account') { + const mapped = applyMapper( + mappers.plaid.account, + op.data.entity as Plaid['schemas']['AccountBase'], + ) + return rxjs.of({ + ...op, + data: { + id: mapped.id, + entityName: 'banking_account', + entity: {raw: op.data.entity, unified: mapped}, + } satisfies PostgresInputPayload, + }) + } } // Do not allow any other entities to pass through return rxjs.EMPTY @@ -199,5 +215,15 @@ const mappers = { merchant_name: 'merchant_name', }, ), + account: mapper( + zCast>(), + zBanking.account, + { + id: 'account_id', + name: 'name', + current_balance: (a) => a.balances.current ?? undefined, + currency: (a) => a.balances.iso_currency_code ?? undefined, + }, + ), }, }