feat: add bank balance column to account

This commit is contained in:
Ahmed Bouhuolia
2024-02-04 22:16:03 +02:00
parent 6d888060d3
commit 2e0b3d0d5e
8 changed files with 38 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
exports.up = function (knex) { exports.up = function (knex) {
return knex.schema.table('accounts', (table) => { return knex.schema.table('accounts', (table) => {
table.string('plaid_account_id'); table.string('plaid_account_id');
table.string('account_mask').nullable();
table.decimal('bank_balance', 15, 5);
}); });
}; };

View File

@@ -0,0 +1,7 @@
exports.up = function (knex) {
return knex.schema.table('cashflow_transactions', (table) => {
table.string('plaid_transaction_id');
});
};
exports.down = function (knex) {};

View File

@@ -8,6 +8,8 @@ export interface IAccountDTO {
accountType: string; accountType: string;
parentAccountId?: number; parentAccountId?: number;
active: boolean; active: boolean;
bankBalance?: number;
accountMask?: string;
} }
export interface IAccountCreateDTO extends IAccountDTO { export interface IAccountCreateDTO extends IAccountDTO {
@@ -34,6 +36,7 @@ export interface IAccount {
type?: any[]; type?: any[];
accountNormal: string; accountNormal: string;
accountParentType: string; accountParentType: string;
bankBalance: string;
} }
export enum AccountNormal { export enum AccountNormal {
@@ -155,10 +158,9 @@ export enum AccountAction {
TransactionsLocking = 'TransactionsLocking', TransactionsLocking = 'TransactionsLocking',
} }
export enum TaxRateAction { export enum TaxRateAction {
CREATE = 'Create', CREATE = 'Create',
EDIT = 'Edit', EDIT = 'Edit',
DELETE = 'Delete', DELETE = 'Delete',
VIEW = 'View', VIEW = 'View',
} }

View File

@@ -45,6 +45,7 @@ export interface ICashflowCommandDTO {
publish: boolean; publish: boolean;
branchId?: number; branchId?: number;
plaidTransactionId?: string;
} }
export interface ICashflowNewCommandDTO extends ICashflowCommandDTO { export interface ICashflowNewCommandDTO extends ICashflowCommandDTO {

View File

@@ -13,7 +13,7 @@ export class AccountTransformer extends Transformer {
* @returns {Array} * @returns {Array}
*/ */
public includeAttributes = (): string[] => { public includeAttributes = (): string[] => {
return ['formattedAmount', 'flattenName']; return ['formattedAmount', 'flattenName', 'bankBalanceFormatted'];
}; };
/** /**
@@ -41,6 +41,17 @@ export class AccountTransformer extends Transformer {
return formatNumber(account.amount, { currencyCode: account.currencyCode }); return formatNumber(account.amount, { currencyCode: account.currencyCode });
}; };
/**
* Retrieves the formatted bank balance.
* @param {IAccount} account
* @returns {string}
*/
protected bankBalanceFormatted = (account: IAccount): string => {
return formatNumber(account.bankBalance, {
currencyCode: account.currencyCode,
});
};
/** /**
* Transformes the accounts collection to flat or nested array. * Transformes the accounts collection to flat or nested array.
* @param {IAccount[]} * @param {IAccount[]}

View File

@@ -27,7 +27,7 @@ export class PlaidApplication {
* @param {PlaidItemDTO} itemDTO * @param {PlaidItemDTO} itemDTO
* @returns * @returns
*/ */
public exchangeToken(tenantId: number, itemDTO: PlaidItemDTO) { public exchangeToken(tenantId: number, itemDTO: PlaidItemDTO): Promise<void> {
return this.plaidItemService.item(tenantId, itemDTO); return this.plaidItemService.item(tenantId, itemDTO);
} }
} }

View File

@@ -1,6 +1,10 @@
import * as R from 'ramda'; import * as R from 'ramda';
import { IAccountCreateDTO, ICashflowNewCommandDTO } from '@/interfaces'; import {
import { PlaidAccount, PlaidTransaction } from './_types'; IAccountCreateDTO,
ICashflowNewCommandDTO,
PlaidAccount,
PlaidTransaction,
} from '@/interfaces';
/** /**
* Transformes the Plaid account to create cashflow account DTO. * Transformes the Plaid account to create cashflow account DTO.
@@ -18,6 +22,8 @@ export const transformPlaidAccountToCreateAccount = (
accountType: 'cash', accountType: 'cash',
active: true, active: true,
plaidAccountId: plaidAccount.account_id, plaidAccountId: plaidAccount.account_id,
bankBalance: plaidAccount.balances.current,
accountMask: plaidAccount.mask,
}; };
}; };
@@ -48,6 +54,7 @@ export const transformPlaidTrxsToCashflowCreate = R.curry(
// transactionNumber: string; // transactionNumber: string;
// referenceNo: string; // referenceNo: string;
plaidTransactionId: plaidTranasction.transaction_id,
publish: true, publish: true,
}; };
} }

View File

@@ -86,7 +86,7 @@ export default class NewCashflowTransactionService {
'cashflowAccountId', 'cashflowAccountId',
'creditAccountId', 'creditAccountId',
'branchId', 'branchId',
'plaidAccountId' 'plaidTransactionId',
]); ]);
// Retreive the next invoice number. // Retreive the next invoice number.
const autoNextNumber = const autoNextNumber =
@@ -125,7 +125,7 @@ export default class NewCashflowTransactionService {
public newCashflowTransaction = async ( public newCashflowTransaction = async (
tenantId: number, tenantId: number,
newTransactionDTO: ICashflowNewCommandDTO, newTransactionDTO: ICashflowNewCommandDTO,
userId?: number userId?: number
): Promise<{ cashflowTransaction: ICashflowTransaction }> => { ): Promise<{ cashflowTransaction: ICashflowTransaction }> => {
const { CashflowTransaction, Account } = this.tenancy.models(tenantId); const { CashflowTransaction, Account } = this.tenancy.models(tenantId);