mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
Compare commits
1 Commits
v0.18.1
...
fix-plaid-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59168bc691 |
@@ -1,3 +1,4 @@
|
|||||||
|
import { Knex } from 'knex';
|
||||||
import {
|
import {
|
||||||
IFinancialSheetCommonMeta,
|
IFinancialSheetCommonMeta,
|
||||||
INumberFormatQuery,
|
INumberFormatQuery,
|
||||||
@@ -257,7 +258,6 @@ export interface IUncategorizedCashflowTransaction {
|
|||||||
categorized: boolean;
|
categorized: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface CreateUncategorizedTransactionDTO {
|
export interface CreateUncategorizedTransactionDTO {
|
||||||
date: Date | string;
|
date: Date | string;
|
||||||
accountId: number;
|
accountId: number;
|
||||||
@@ -269,3 +269,16 @@ export interface CreateUncategorizedTransactionDTO {
|
|||||||
plaidTransactionId?: string | null;
|
plaidTransactionId?: string | null;
|
||||||
batch?: string;
|
batch?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IUncategorizedTransactionCreatingEventPayload {
|
||||||
|
tenantId: number;
|
||||||
|
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO;
|
||||||
|
trx: Knex.Transaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IUncategorizedTransactionCreatedEventPayload {
|
||||||
|
tenantId: number;
|
||||||
|
uncategorizedTransaction: any;
|
||||||
|
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO;
|
||||||
|
trx: Knex.Transaction;
|
||||||
|
}
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ export class PlaidSyncDb {
|
|||||||
*/
|
*/
|
||||||
public async syncAccountsTransactions(
|
public async syncAccountsTransactions(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
batchNo: string,
|
|
||||||
plaidAccountsTransactions: PlaidTransaction[],
|
plaidAccountsTransactions: PlaidTransaction[],
|
||||||
trx?: Knex.Transaction
|
trx?: Knex.Transaction
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@@ -161,7 +160,6 @@ export class PlaidSyncDb {
|
|||||||
return this.syncAccountTranactions(
|
return this.syncAccountTranactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
plaidAccountId,
|
plaidAccountId,
|
||||||
batchNo,
|
|
||||||
plaidTransactions,
|
plaidTransactions,
|
||||||
trx
|
trx
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export const transformPlaidAccountToCreateAccount = R.curry(
|
|||||||
export const transformPlaidTrxsToCashflowCreate = R.curry(
|
export const transformPlaidTrxsToCashflowCreate = R.curry(
|
||||||
(
|
(
|
||||||
cashflowAccountId: number,
|
cashflowAccountId: number,
|
||||||
creditAccountId: number,
|
|
||||||
plaidTranasction: PlaidTransaction
|
plaidTranasction: PlaidTransaction
|
||||||
): CreateUncategorizedTransactionDTO => {
|
): CreateUncategorizedTransactionDTO => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ import { Knex } from 'knex';
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import HasTenancyService from '../Tenancy/TenancyService';
|
import HasTenancyService from '../Tenancy/TenancyService';
|
||||||
import UnitOfWork from '../UnitOfWork';
|
import UnitOfWork from '../UnitOfWork';
|
||||||
import { CreateUncategorizedTransactionDTO } from '@/interfaces';
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import events from '@/subscribers/events';
|
||||||
|
import {
|
||||||
|
CreateUncategorizedTransactionDTO,
|
||||||
|
IUncategorizedTransactionCreatedEventPayload,
|
||||||
|
IUncategorizedTransactionCreatingEventPayload,
|
||||||
|
} from '@/interfaces';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class CreateUncategorizedTransaction {
|
export class CreateUncategorizedTransaction {
|
||||||
@@ -12,6 +18,9 @@ export class CreateUncategorizedTransaction {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private uow: UnitOfWork;
|
private uow: UnitOfWork;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private eventPublisher: EventPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an uncategorized cashflow transaction.
|
* Creates an uncategorized cashflow transaction.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -19,7 +28,7 @@ export class CreateUncategorizedTransaction {
|
|||||||
*/
|
*/
|
||||||
public create(
|
public create(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
createDTO: CreateUncategorizedTransactionDTO,
|
createUncategorizedTransactionDTO: CreateUncategorizedTransactionDTO,
|
||||||
trx?: Knex.Transaction
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
||||||
@@ -27,12 +36,30 @@ export class CreateUncategorizedTransaction {
|
|||||||
return this.uow.withTransaction(
|
return this.uow.withTransaction(
|
||||||
tenantId,
|
tenantId,
|
||||||
async (trx: Knex.Transaction) => {
|
async (trx: Knex.Transaction) => {
|
||||||
const transaction = await UncategorizedCashflowTransaction.query(
|
await this.eventPublisher.emitAsync(
|
||||||
trx
|
events.cashflow.onTransactionUncategorizedCreated,
|
||||||
).insertAndFetch({
|
{
|
||||||
...createDTO,
|
tenantId,
|
||||||
});
|
createUncategorizedTransactionDTO,
|
||||||
return transaction;
|
trx,
|
||||||
|
} as IUncategorizedTransactionCreatingEventPayload
|
||||||
|
);
|
||||||
|
|
||||||
|
const uncategorizedTransaction =
|
||||||
|
await UncategorizedCashflowTransaction.query(trx).insertAndFetch({
|
||||||
|
...createUncategorizedTransactionDTO,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.eventPublisher.emitAsync(
|
||||||
|
events.cashflow.onTransactionUncategorizedCreated,
|
||||||
|
{
|
||||||
|
tenantId,
|
||||||
|
uncategorizedTransaction,
|
||||||
|
createUncategorizedTransactionDTO,
|
||||||
|
trx,
|
||||||
|
} as IUncategorizedTransactionCreatedEventPayload
|
||||||
|
);
|
||||||
|
return uncategorizedTransaction;
|
||||||
},
|
},
|
||||||
trx
|
trx
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ export class DecrementUncategorizedTransactionOnCategorize {
|
|||||||
events.cashflow.onTransactionUncategorized,
|
events.cashflow.onTransactionUncategorized,
|
||||||
this.incrementUnCategorizedTransactionsOnUncategorized.bind(this)
|
this.incrementUnCategorizedTransactionsOnUncategorized.bind(this)
|
||||||
);
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.cashflow.onTransactionUncategorizedCreated,
|
||||||
|
this.incrementUncategoirzedTransactionsOnCreated.bind(this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,4 +57,22 @@ export class DecrementUncategorizedTransactionOnCategorize {
|
|||||||
.findById(uncategorizedTransaction.accountId)
|
.findById(uncategorizedTransaction.accountId)
|
||||||
.increment('uncategorizedTransactions', 1);
|
.increment('uncategorizedTransactions', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments uncategorized transactions count once creating a new transaction.
|
||||||
|
* @param {ICommandCashflowCreatedPayload} payload -
|
||||||
|
*/
|
||||||
|
public async incrementUncategoirzedTransactionsOnCreated({
|
||||||
|
tenantId,
|
||||||
|
uncategorizedTransaction,
|
||||||
|
trx,
|
||||||
|
}: any) {
|
||||||
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
|
if (!uncategorizedTransaction.accountId) return;
|
||||||
|
|
||||||
|
await Account.query(trx)
|
||||||
|
.findById(uncategorizedTransaction.accountId)
|
||||||
|
.increment('uncategorizedTransactions', 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -399,6 +399,9 @@ export default {
|
|||||||
onTransactionCategorizing: 'onTransactionCategorizing',
|
onTransactionCategorizing: 'onTransactionCategorizing',
|
||||||
onTransactionCategorized: 'onCashflowTransactionCategorized',
|
onTransactionCategorized: 'onCashflowTransactionCategorized',
|
||||||
|
|
||||||
|
onTransactionUncategorizedCreating: 'onTransactionUncategorizedCreating',
|
||||||
|
onTransactionUncategorizedCreated: 'onTransactionUncategorizedCreated',
|
||||||
|
|
||||||
onTransactionUncategorizing: 'onTransactionUncategorizing',
|
onTransactionUncategorizing: 'onTransactionUncategorizing',
|
||||||
onTransactionUncategorized: 'onTransactionUncategorized',
|
onTransactionUncategorized: 'onTransactionUncategorized',
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user