Files
bigcapital/packages/server/src/services/Banking/Matching/events/ValidateMatchingOnCashflowDelete.ts
2024-07-06 19:10:07 +02:00

38 lines
1.0 KiB
TypeScript

import { Inject, Service } from 'typedi';
import { ICommandCashflowDeletingPayload, IManualJournalDeletingPayload } from '@/interfaces';
import events from '@/subscribers/events';
import { ValidateTransactionMatched } from '../ValidateTransactionsMatched';
@Service()
export class ValidateMatchingOnCashflowDelete {
@Inject()
private validateNoMatchingLinkedService: ValidateTransactionMatched;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.cashflow.onTransactionDeleting,
this.validateMatchingOnCashflowDeleting.bind(this)
);
}
/**
* Validates the cashflow transaction whether matched with bank transaction on deleting.
* @param {IManualJournalDeletingPayload}
*/
public async validateMatchingOnCashflowDeleting({
tenantId,
oldCashflowTransaction,
trx,
}: ICommandCashflowDeletingPayload) {
await this.validateNoMatchingLinkedService.validateTransactionNoMatchLinking(
tenantId,
'CashflowTransaction',
oldCashflowTransaction.id,
trx
);
}
}