mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ExcludeBankTransactionsApplication } from './ExcludeBankTransactionsApplication';
|
||||
import { ExcludedBankTransactionsQuery } from './types/BankTransactionsExclude.types';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@Controller('banking/transactions')
|
||||
@ApiTags('banking-transactions')
|
||||
export class BankingTransactionsExcludeController {
|
||||
constructor(
|
||||
private readonly excludeBankTransactionsApplication: ExcludeBankTransactionsApplication,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Retrieves the excluded bank transactions.' })
|
||||
public getExcludedBankTransactions(
|
||||
@Query() query: ExcludedBankTransactionsQuery,
|
||||
) {
|
||||
return this.excludeBankTransactionsApplication.getExcludedBankTransactions(
|
||||
query,
|
||||
);
|
||||
}
|
||||
|
||||
@Post(':id/exclude')
|
||||
@ApiOperation({ summary: 'Exclude the given bank transaction.' })
|
||||
public excludeBankTransaction(@Param('id') id: string) {
|
||||
return this.excludeBankTransactionsApplication.excludeBankTransaction(
|
||||
Number(id),
|
||||
);
|
||||
}
|
||||
|
||||
@Delete(':id/exclude')
|
||||
@ApiOperation({ summary: 'Unexclude the given bank transaction.' })
|
||||
public unexcludeBankTransaction(@Param('id') id: string) {
|
||||
return this.excludeBankTransactionsApplication.unexcludeBankTransaction(
|
||||
Number(id),
|
||||
);
|
||||
}
|
||||
|
||||
@Post('bulk/exclude')
|
||||
@ApiOperation({ summary: 'Exclude the given bank transactions.' })
|
||||
public excludeBankTransactions(@Body('ids') ids: number[]) {
|
||||
return this.excludeBankTransactionsApplication.excludeBankTransactions(ids);
|
||||
}
|
||||
|
||||
@Delete('bulk/exclude')
|
||||
@ApiOperation({ summary: 'Unexclude the given bank transactions.' })
|
||||
public unexcludeBankTransactions(@Body('ids') ids: number[]) {
|
||||
return this.excludeBankTransactionsApplication.unexcludeBankTransactions(
|
||||
ids,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ExcludeBankTransactionsApplication } from './ExcludeBankTransactionsApplication';
|
||||
import { ExcludeBankTransactionService } from './commands/ExcludeBankTransaction.service';
|
||||
import { UnexcludeBankTransactionService } from './commands/UnexcludeBankTransaction.service';
|
||||
import { GetExcludedBankTransactionsService } from './queries/GetExcludedBankTransactions';
|
||||
import { ExcludeBankTransactionsService } from './commands/ExcludeBankTransactions.service';
|
||||
import { UnexcludeBankTransactionsService } from './commands/UnexcludeBankTransactions.service';
|
||||
import { DecrementUncategorizedTransactionOnExclude } from './subscribers/DecrementUncategorizedTransactionOnExclude';
|
||||
import { BankingTransactionsExcludeController } from './BankingTransactionsExclude.controller';
|
||||
import { BankingTransactionsModule } from '../BankingTransactions/BankingTransactions.module';
|
||||
|
||||
@Module({
|
||||
imports: [BankingTransactionsModule],
|
||||
providers: [
|
||||
ExcludeBankTransactionsApplication,
|
||||
ExcludeBankTransactionService,
|
||||
UnexcludeBankTransactionService,
|
||||
GetExcludedBankTransactionsService,
|
||||
ExcludeBankTransactionsService,
|
||||
UnexcludeBankTransactionsService,
|
||||
DecrementUncategorizedTransactionOnExclude
|
||||
],
|
||||
controllers: [BankingTransactionsExcludeController],
|
||||
})
|
||||
export class BankingTransactionsExcludeModule {}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { ExcludeBankTransactionService } from './commands/ExcludeBankTransaction.service';
|
||||
import { UnexcludeBankTransactionService } from './commands/UnexcludeBankTransaction.service';
|
||||
import { GetExcludedBankTransactionsService } from './queries/GetExcludedBankTransactions';
|
||||
import { ExcludedBankTransactionsQuery } from './types/BankTransactionsExclude.types';
|
||||
import { UnexcludeBankTransactionsService } from './commands/UnexcludeBankTransactions.service';
|
||||
import { ExcludeBankTransactionsService } from './commands/ExcludeBankTransactions.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class ExcludeBankTransactionsApplication {
|
||||
constructor(
|
||||
private readonly excludeBankTransactionService: ExcludeBankTransactionService,
|
||||
private readonly unexcludeBankTransactionService: UnexcludeBankTransactionService,
|
||||
private readonly getExcludedBankTransactionsService: GetExcludedBankTransactionsService,
|
||||
private readonly excludeBankTransactionsService: ExcludeBankTransactionsService,
|
||||
private readonly unexcludeBankTransactionsService: UnexcludeBankTransactionsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Marks a bank transaction as excluded.
|
||||
* @param {number} bankTransactionId - The ID of the bank transaction to exclude.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public excludeBankTransaction(bankTransactionId: number) {
|
||||
return this.excludeBankTransactionService.excludeBankTransaction(
|
||||
bankTransactionId,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a bank transaction as not excluded.
|
||||
* @param {number} bankTransactionId - The ID of the bank transaction to exclude.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public unexcludeBankTransaction(bankTransactionId: number) {
|
||||
return this.unexcludeBankTransactionService.unexcludeBankTransaction(
|
||||
bankTransactionId,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the excluded bank transactions.
|
||||
* @param {ExcludedBankTransactionsQuery} filter
|
||||
* @returns {}
|
||||
*/
|
||||
public getExcludedBankTransactions(filter: ExcludedBankTransactionsQuery) {
|
||||
return this.getExcludedBankTransactionsService.getExcludedBankTransactions(
|
||||
filter,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude the given bank transactions in bulk.
|
||||
* @param {Array<number> | number} bankTransactionIds
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public excludeBankTransactions(
|
||||
bankTransactionIds: Array<number> | number,
|
||||
): Promise<void> {
|
||||
return this.excludeBankTransactionsService.excludeBankTransactions(
|
||||
bankTransactionIds,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude the given bank transactions in bulk.
|
||||
* @param {Array<number> | number} bankTransactionIds
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public unexcludeBankTransactions(
|
||||
bankTransactionIds: Array<number> | number,
|
||||
): Promise<void> {
|
||||
return this.unexcludeBankTransactionsService.unexcludeBankTransactions(
|
||||
bankTransactionIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { UncategorizedBankTransaction } from '@/modules/BankingTransactions/models/UncategorizedBankTransaction';
|
||||
import {
|
||||
validateTransactionNotCategorized,
|
||||
validateTransactionNotExcluded,
|
||||
} from './utils';
|
||||
import {
|
||||
IBankTransactionUnexcludedEventPayload,
|
||||
IBankTransactionUnexcludingEventPayload,
|
||||
} from '../types/BankTransactionsExclude.types';
|
||||
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class ExcludeBankTransactionService {
|
||||
constructor(
|
||||
@Inject(UncategorizedBankTransaction.name)
|
||||
private uncategorizedBankTransactionModel: TenantModelProxy<
|
||||
typeof UncategorizedBankTransaction
|
||||
>,
|
||||
|
||||
private uow: UnitOfWork,
|
||||
private eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Marks the given bank transaction as excluded.
|
||||
* @param {number} uncategorizedTransactionId - Uncategorized bank transaction identifier.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async excludeBankTransaction(uncategorizedTransactionId: number) {
|
||||
const oldUncategorizedTransaction =
|
||||
await this.uncategorizedBankTransactionModel()
|
||||
.query()
|
||||
.findById(uncategorizedTransactionId)
|
||||
.throwIfNotFound();
|
||||
|
||||
// Validate the transaction shouldn't be excluded.
|
||||
validateTransactionNotExcluded(oldUncategorizedTransaction);
|
||||
|
||||
// Validate the transaction shouldn't be categorized.
|
||||
validateTransactionNotCategorized(oldUncategorizedTransaction);
|
||||
|
||||
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
|
||||
await this.eventEmitter.emitAsync(events.bankTransactions.onExcluding, {
|
||||
uncategorizedTransactionId,
|
||||
trx,
|
||||
} as IBankTransactionUnexcludingEventPayload);
|
||||
|
||||
await this.uncategorizedBankTransactionModel()
|
||||
.query(trx)
|
||||
.findById(uncategorizedTransactionId)
|
||||
.patch({
|
||||
excludedAt: new Date(),
|
||||
});
|
||||
|
||||
await this.eventEmitter.emitAsync(events.bankTransactions.onExcluded, {
|
||||
uncategorizedTransactionId,
|
||||
trx,
|
||||
} as IBankTransactionUnexcludedEventPayload);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import PromisePool from '@supercharge/promise-pool';
|
||||
import { castArray, uniq } from 'lodash';
|
||||
import { ExcludeBankTransactionService } from './ExcludeBankTransaction.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class ExcludeBankTransactionsService {
|
||||
constructor(
|
||||
private readonly excludeBankTransaction: ExcludeBankTransactionService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Exclude bank transactions in bulk.
|
||||
* @param {Array<number> | number} bankTransactionIds - The IDs of the bank transactions to exclude.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async excludeBankTransactions(
|
||||
bankTransactionIds: Array<number> | number,
|
||||
) {
|
||||
const _bankTransactionIds = uniq(castArray(bankTransactionIds));
|
||||
|
||||
await PromisePool.withConcurrency(1)
|
||||
.for(_bankTransactionIds)
|
||||
.process((bankTransactionId: number) => {
|
||||
return this.excludeBankTransaction.excludeBankTransaction(
|
||||
bankTransactionId,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Knex } from 'knex';
|
||||
import {
|
||||
validateTransactionNotCategorized,
|
||||
validateTransactionShouldBeExcluded,
|
||||
} from './utils';
|
||||
import {
|
||||
IBankTransactionExcludedEventPayload,
|
||||
IBankTransactionExcludingEventPayload,
|
||||
} from '../types/BankTransactionsExclude.types';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { UncategorizedBankTransaction } from '@/modules/BankingTransactions/models/UncategorizedBankTransaction';
|
||||
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
|
||||
import { events } from '@/common/events/events';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class UnexcludeBankTransactionService {
|
||||
constructor(
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
private readonly uow: UnitOfWork,
|
||||
|
||||
@Inject(UncategorizedBankTransaction.name)
|
||||
private readonly uncategorizedBankTransactionModel: TenantModelProxy<
|
||||
typeof UncategorizedBankTransaction
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Marks the given bank transaction as excluded.
|
||||
* @param {number} tenantId
|
||||
* @param {number} bankTransactionId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async unexcludeBankTransaction(
|
||||
uncategorizedTransactionId: number,
|
||||
): Promise<void> {
|
||||
const oldUncategorizedTransaction =
|
||||
await this.uncategorizedBankTransactionModel()
|
||||
.query()
|
||||
.findById(uncategorizedTransactionId)
|
||||
.throwIfNotFound();
|
||||
|
||||
// Validate the transaction should be excludded.
|
||||
validateTransactionShouldBeExcluded(oldUncategorizedTransaction);
|
||||
|
||||
// Validate the transaction shouldn't be categorized.
|
||||
validateTransactionNotCategorized(oldUncategorizedTransaction);
|
||||
|
||||
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
|
||||
await this.eventEmitter.emitAsync(events.bankTransactions.onUnexcluding, {
|
||||
uncategorizedTransactionId,
|
||||
} as IBankTransactionExcludingEventPayload);
|
||||
|
||||
await this.uncategorizedBankTransactionModel()
|
||||
.query(trx)
|
||||
.findById(uncategorizedTransactionId)
|
||||
.patch({
|
||||
excludedAt: null,
|
||||
});
|
||||
|
||||
await this.eventEmitter.emitAsync(events.bankTransactions.onUnexcluded, {
|
||||
uncategorizedTransactionId,
|
||||
} as IBankTransactionExcludedEventPayload);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PromisePool } from '@supercharge/promise-pool';
|
||||
import { castArray, uniq } from 'lodash';
|
||||
import { UnexcludeBankTransactionService } from './UnexcludeBankTransaction.service';
|
||||
|
||||
@Injectable()
|
||||
export class UnexcludeBankTransactionsService {
|
||||
constructor(
|
||||
private readonly unexcludeBankTransaction: UnexcludeBankTransactionService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Unexclude bank transactions in bulk.
|
||||
* @param {Array<number> | number} bankTransactionIds - The IDs of the bank transactions to unexclude.
|
||||
*/
|
||||
public async unexcludeBankTransactions(
|
||||
bankTransactionIds: Array<number> | number
|
||||
) {
|
||||
const _bankTransactionIds = uniq(castArray(bankTransactionIds));
|
||||
|
||||
await PromisePool.withConcurrency(1)
|
||||
.for(_bankTransactionIds)
|
||||
.process((bankTransactionId: number) => {
|
||||
return this.unexcludeBankTransaction.unexcludeBankTransaction(
|
||||
bankTransactionId
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { UncategorizedBankTransaction } from "@/modules/BankingTransactions/models/UncategorizedBankTransaction";
|
||||
import { ServiceError } from "@/modules/Items/ServiceError";
|
||||
|
||||
const ERRORS = {
|
||||
TRANSACTION_ALREADY_CATEGORIZED: 'TRANSACTION_ALREADY_CATEGORIZED',
|
||||
TRANSACTION_ALREADY_EXCLUDED: 'TRANSACTION_ALREADY_EXCLUDED',
|
||||
TRANSACTION_NOT_EXCLUDED: 'TRANSACTION_NOT_EXCLUDED',
|
||||
};
|
||||
|
||||
export const validateTransactionNotCategorized = (
|
||||
transaction: UncategorizedBankTransaction
|
||||
) => {
|
||||
if (transaction.categorized) {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
|
||||
}
|
||||
};
|
||||
|
||||
export const validateTransactionNotExcluded = (
|
||||
transaction: UncategorizedBankTransaction
|
||||
) => {
|
||||
if (transaction.isExcluded) {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_EXCLUDED);
|
||||
}
|
||||
};
|
||||
|
||||
export const validateTransactionShouldBeExcluded = (
|
||||
transaction: UncategorizedBankTransaction
|
||||
) => {
|
||||
if (!transaction.isExcluded) {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_NOT_EXCLUDED);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { ExcludedBankTransactionsQuery } from '../types/BankTransactionsExclude.types';
|
||||
import { UncategorizedTransactionTransformer } from '@/modules/BankingCategorize/commands/UncategorizedTransaction.transformer';
|
||||
import { UncategorizedBankTransaction } from '@/modules/BankingTransactions/models/UncategorizedBankTransaction';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetExcludedBankTransactionsService {
|
||||
/**
|
||||
* @param {TransformerInjectable} transformer
|
||||
* @param {TenantModelProxy<typeof UncategorizedBankTransaction>} uncategorizedBankTransaction
|
||||
*/
|
||||
constructor(
|
||||
private readonly transformer: TransformerInjectable,
|
||||
|
||||
@Inject(UncategorizedBankTransaction.name)
|
||||
private readonly uncategorizedBankTransaction: TenantModelProxy<
|
||||
typeof UncategorizedBankTransaction
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieves the excluded uncategorized bank transactions.
|
||||
* @param {ExcludedBankTransactionsQuery} filter
|
||||
* @returns
|
||||
*/
|
||||
public async getExcludedBankTransactions(
|
||||
filter: ExcludedBankTransactionsQuery,
|
||||
) {
|
||||
// Parsed query with default values.
|
||||
const _query = {
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
...filter,
|
||||
};
|
||||
const { results, pagination } = await this.uncategorizedBankTransaction()
|
||||
.query()
|
||||
.onBuild((q) => {
|
||||
q.modify('excluded');
|
||||
q.orderBy('date', 'DESC');
|
||||
|
||||
if (_query.accountId) {
|
||||
q.where('account_id', _query.accountId);
|
||||
}
|
||||
if (_query.minDate) {
|
||||
q.modify('fromDate', _query.minDate);
|
||||
}
|
||||
if (_query.maxDate) {
|
||||
q.modify('toDate', _query.maxDate);
|
||||
}
|
||||
if (_query.minAmount) {
|
||||
q.modify('minAmount', _query.minAmount);
|
||||
}
|
||||
if (_query.maxAmount) {
|
||||
q.modify('maxAmount', _query.maxAmount);
|
||||
}
|
||||
})
|
||||
.pagination(_query.page - 1, _query.pageSize);
|
||||
|
||||
const data = await this.transformer.transform(
|
||||
results,
|
||||
new UncategorizedTransactionTransformer(),
|
||||
);
|
||||
return { data, pagination };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
IBankTransactionExcludedEventPayload,
|
||||
IBankTransactionUnexcludedEventPayload,
|
||||
} from '../types/BankTransactionsExclude.types';
|
||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||
import { UncategorizedBankTransaction } from '@/modules/BankingTransactions/models/UncategorizedBankTransaction';
|
||||
import { events } from '@/common/events/events';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class DecrementUncategorizedTransactionOnExclude {
|
||||
constructor(
|
||||
@Inject(Account.name)
|
||||
private readonly account: TenantModelProxy<typeof Account>,
|
||||
|
||||
@Inject(UncategorizedBankTransaction.name)
|
||||
private readonly uncategorizedBankTransaction: TenantModelProxy<
|
||||
typeof UncategorizedBankTransaction
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Validates the cashflow transaction whether matched with bank transaction on deleting.
|
||||
* @param {IManualJournalDeletingPayload}
|
||||
*/
|
||||
@OnEvent(events.bankTransactions.onExcluded)
|
||||
public async decrementUnCategorizedTransactionsOnExclude({
|
||||
uncategorizedTransactionId,
|
||||
trx,
|
||||
}: IBankTransactionExcludedEventPayload) {
|
||||
const transaction = await this.uncategorizedBankTransaction()
|
||||
.query(trx)
|
||||
.findById(uncategorizedTransactionId);
|
||||
|
||||
await this.account()
|
||||
.query(trx)
|
||||
.findById(transaction.accountId)
|
||||
.decrement('uncategorizedTransactions', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the cashflow transaction whether matched with bank transaction on deleting.
|
||||
* @param {IManualJournalDeletingPayload}
|
||||
*/
|
||||
@OnEvent(events.bankTransactions.onUnexcluded)
|
||||
public async incrementUnCategorizedTransactionsOnUnexclude({
|
||||
uncategorizedTransactionId,
|
||||
trx,
|
||||
}: IBankTransactionUnexcludedEventPayload) {
|
||||
const transaction = await this.uncategorizedBankTransaction()
|
||||
.query()
|
||||
.findById(uncategorizedTransactionId);
|
||||
//
|
||||
await this.account()
|
||||
.query(trx)
|
||||
.findById(transaction.accountId)
|
||||
.increment('uncategorizedTransactions', 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
export interface ExcludedBankTransactionsQuery {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
accountId?: number;
|
||||
minDate?: Date;
|
||||
maxDate?: Date;
|
||||
minAmount?: number;
|
||||
maxAmount?: number;
|
||||
}
|
||||
|
||||
export interface IBankTransactionUnexcludingEventPayload {
|
||||
uncategorizedTransactionId: number;
|
||||
trx?: Knex.Transaction
|
||||
}
|
||||
|
||||
export interface IBankTransactionUnexcludedEventPayload {
|
||||
uncategorizedTransactionId: number;
|
||||
trx?: Knex.Transaction
|
||||
}
|
||||
|
||||
export interface IBankTransactionExcludingEventPayload {
|
||||
uncategorizedTransactionId: number;
|
||||
trx?: Knex.Transaction
|
||||
}
|
||||
export interface IBankTransactionExcludedEventPayload {
|
||||
uncategorizedTransactionId: number;
|
||||
trx?: Knex.Transaction
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { UncategorizedBankTransaction } from '../BankingTransactions/models/UncategorizedBankTransaction';
|
||||
import { ServiceError } from '../Items/ServiceError';
|
||||
|
||||
const ERRORS = { TRANSACTION_ALREADY_CATEGORIZED: 'TRANSACTION_ALREADY_CATEGORIZED',
|
||||
TRANSACTION_ALREADY_EXCLUDED: 'TRANSACTION_ALREADY_EXCLUDED',
|
||||
TRANSACTION_NOT_EXCLUDED: 'TRANSACTION_NOT_EXCLUDED',
|
||||
};
|
||||
|
||||
export const validateTransactionNotCategorized = (
|
||||
transaction: UncategorizedBankTransaction,
|
||||
) => {
|
||||
if (transaction.categorized) {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_CATEGORIZED);
|
||||
}
|
||||
};
|
||||
|
||||
export const validateTransactionNotExcluded = (
|
||||
transaction: UncategorizedBankTransaction,
|
||||
) => {
|
||||
if (transaction.isExcluded) {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_ALREADY_EXCLUDED);
|
||||
}
|
||||
};
|
||||
|
||||
export const validateTransactionShouldBeExcluded = (
|
||||
transaction: UncategorizedBankTransaction,
|
||||
) => {
|
||||
if (!transaction.isExcluded) {
|
||||
throw new ServiceError(ERRORS.TRANSACTION_NOT_EXCLUDED);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user