mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat(server): sync Plaid transactions to uncategorized transactions
This commit is contained in:
@@ -4,10 +4,13 @@ import { UncategorizeCashflowTransaction } from './UncategorizeCashflowTransacti
|
||||
import { CategorizeCashflowTransaction } from './CategorizeCashflowTransaction';
|
||||
import {
|
||||
CategorizeTransactionAsExpenseDTO,
|
||||
CreateUncategorizedTransactionDTO,
|
||||
ICategorizeCashflowTransactioDTO,
|
||||
IUncategorizedCashflowTransaction,
|
||||
} from '@/interfaces';
|
||||
import { CategorizeTransactionAsExpense } from './CategorizeTransactionAsExpense';
|
||||
import { GetUncategorizedTransactions } from './GetUncategorizedTransactions';
|
||||
import { CreateUncategorizedTransaction } from './CreateUncategorizedTransaction';
|
||||
|
||||
@Service()
|
||||
export class CashflowApplication {
|
||||
@@ -26,6 +29,9 @@ export class CashflowApplication {
|
||||
@Inject()
|
||||
private getUncategorizedTransactionsService: GetUncategorizedTransactions;
|
||||
|
||||
@Inject()
|
||||
private createUncategorizedTransactionService: CreateUncategorizedTransaction;
|
||||
|
||||
/**
|
||||
* Deletes the given cashflow transaction.
|
||||
* @param {number} tenantId
|
||||
@@ -39,6 +45,22 @@ export class CashflowApplication {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new uncategorized cash transaction.
|
||||
* @param {number} tenantId
|
||||
* @param {CreateUncategorizedTransactionDTO} createUncategorizedTransactionDTO
|
||||
* @returns {IUncategorizedCashflowTransaction}
|
||||
*/
|
||||
public createUncategorizedTransaction(
|
||||
tenantId: number,
|
||||
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO
|
||||
) {
|
||||
return this.createUncategorizedTransactionService.create(
|
||||
tenantId,
|
||||
createUncategorizedTransactionDTO
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uncategorize the given cashflow transaction.
|
||||
* @param {number} tenantId
|
||||
@@ -98,7 +120,10 @@ export class CashflowApplication {
|
||||
* @param {number} tenantId
|
||||
* @returns {}
|
||||
*/
|
||||
public getUncategorizedTransactions(tenantId: number) {
|
||||
return this.getUncategorizedTransactionsService.getTransactions(tenantId);
|
||||
public getUncategorizedTransactions(tenantId: number, accountId: number) {
|
||||
return this.getUncategorizedTransactionsService.getTransactions(
|
||||
tenantId,
|
||||
accountId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import UnitOfWork from '../UnitOfWork';
|
||||
import { Knex } from 'knex';
|
||||
import { CreateUncategorizedTransactionDTO } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class CreateUncategorizedTransaction {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private uow: UnitOfWork;
|
||||
|
||||
/**
|
||||
* Creates an uncategorized cashflow transaction.
|
||||
* @param {number} tenantId
|
||||
* @param {CreateUncategorizedTransactionDTO} createDTO
|
||||
*/
|
||||
public create(
|
||||
tenantId: number,
|
||||
createDTO: CreateUncategorizedTransactionDTO
|
||||
) {
|
||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
const transaction = await UncategorizedCashflowTransaction.query(
|
||||
trx
|
||||
).insertAndFetch({
|
||||
...createDTO,
|
||||
});
|
||||
return transaction;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,15 @@ export class GetUncategorizedTransactions {
|
||||
|
||||
/**
|
||||
* Retrieves the uncategorized cashflow transactions.
|
||||
* @param {number} tenantId
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {number} accountId - Account Id.
|
||||
*/
|
||||
public async getTransactions(tenantId: number) {
|
||||
public async getTransactions(tenantId: number, accountId: number) {
|
||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
const { results, pagination } =
|
||||
await UncategorizedCashflowTransaction.query()
|
||||
.where('accountId', accountId)
|
||||
.where('categorized', false)
|
||||
.withGraphFetched('account')
|
||||
.pagination(0, 10);
|
||||
|
||||
@@ -7,9 +7,22 @@ export class UncategorizedTransactionTransformer extends Transformer {
|
||||
* @returns {string[]}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return ['formattetDepositAmount', 'formattedWithdrawalAmount'];
|
||||
return [
|
||||
'formattedDate',
|
||||
'formattetDepositAmount',
|
||||
'formattedWithdrawalAmount',
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Formattes the transaction date.
|
||||
* @param transaction
|
||||
* @returns {string}
|
||||
*/
|
||||
public formattedDate(transaction) {
|
||||
return this.formatDate(transaction.date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted deposit amount.
|
||||
* @param transaction
|
||||
|
||||
Reference in New Issue
Block a user