Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sync Plaid credit card account type #714

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/server/src/data/AccountTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const ACCOUNT_TYPES = [
normal: ACCOUNT_NORMAL.CREDIT,
rootType: ACCOUNT_ROOT_TYPE.LIABILITY,
parentType: ACCOUNT_PARENT_TYPE.CURRENT_LIABILITY,
multiCurrency: true,
balanceSheet: true,
incomeSheet: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default class UncategorizedCashflowTransaction extends mixin(
) {
id!: number;
date!: Date | string;

/**
* Transaction amount.
* Negative represents to spending and positive to deposit/card charge.
* @param {number}
*/
amount!: number;
categorized!: boolean;
accountId!: number;
Expand Down
18 changes: 17 additions & 1 deletion packages/server/src/services/Banking/Plaid/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ import {
Institution as PlaidInstitution,
AccountBase as PlaidAccount,
TransactionBase as PlaidTransactionBase,
AccountType as PlaidAccountType,
} from 'plaid';
import {
CreateUncategorizedTransactionDTO,
IAccountCreateDTO,
} from '@/interfaces';
import { ACCOUNT_TYPE } from '@/data/AccountTypes';

/**
* Retrieves the system account type from the given Plaid account type.
* @param {PlaidAccountType} plaidAccountType
* @returns {string}
*/
const getAccountTypeFromPlaidAccountType = (
plaidAccountType: PlaidAccountType
) => {
if (plaidAccountType === PlaidAccountType.Credit) {
return ACCOUNT_TYPE.CREDIT_CARD;
}
return ACCOUNT_TYPE.BANK;
};

/**
* Transformes the Plaid account to create cashflow account DTO.
Expand All @@ -28,7 +44,7 @@ export const transformPlaidAccountToCreateAccount = R.curry(
code: '',
description: plaidAccount.official_name,
currencyCode: plaidAccount.balances.iso_currency_code,
accountType: 'cash',
accountType: getAccountTypeFromPlaidAccountType(plaidAccount.type),
active: true,
bankBalance: plaidAccount.balances.current,
accountMask: plaidAccount.mask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CashflowAccountTransformer } from './CashflowAccountTransformer';
import TenancyService from '@/services/Tenancy/TenancyService';
import DynamicListingService from '@/services/DynamicListing/DynamicListService';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { ACCOUNT_TYPE } from '@/data/AccountTypes';

@Service()
export default class GetCashflowAccountsService {
Expand Down Expand Up @@ -41,14 +42,20 @@ export default class GetCashflowAccountsService {
const accounts = await CashflowAccount.query().onBuild((builder) => {
dynamicList.buildQuery()(builder);

builder.whereIn('account_type', ['bank', 'cash']);
builder.whereIn('account_type', [
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.CREDIT_CARD,
]);
builder.modify('inactiveMode', filter.inactiveMode);
});
// Retrieves the transformed accounts.
return this.transformer.transform(
const transformed = await this.transformer.transform(
tenantId,
accounts,
new CashflowAccountTransformer()
);

return transformed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class GetCashflowTransactionService {
private tenancy: HasTenancyService;

@Inject()
private transfromer: TransformerInjectable;
private transformer: TransformerInjectable;

/**
* Retrieve the given cashflow transaction.
Expand All @@ -37,7 +37,7 @@ export class GetCashflowTransactionService {
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);

// Transformes the cashflow transaction model to POJO.
return this.transfromer.transform(
return this.transformer.transform(
tenantId,
cashflowTransaction,
new CashflowTransactionTransformer()
Expand Down
Loading