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) {
return knex.schema.table('accounts', (table) => {
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;
parentAccountId?: number;
active: boolean;
bankBalance?: number;
accountMask?: string;
}
export interface IAccountCreateDTO extends IAccountDTO {
@@ -34,6 +36,7 @@ export interface IAccount {
type?: any[];
accountNormal: string;
accountParentType: string;
bankBalance: string;
}
export enum AccountNormal {
@@ -155,10 +158,9 @@ export enum AccountAction {
TransactionsLocking = 'TransactionsLocking',
}
export enum TaxRateAction {
CREATE = 'Create',
EDIT = 'Edit',
DELETE = 'Delete',
VIEW = 'View',
}
}

View File

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

View File

@@ -13,7 +13,7 @@ export class AccountTransformer extends Transformer {
* @returns {Array}
*/
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 });
};
/**
* 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.
* @param {IAccount[]}

View File

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

View File

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

View File

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