feat: validate the matched linked transacation on deleting.

This commit is contained in:
Ahmed Bouhuolia
2024-06-23 14:34:40 +02:00
parent ca403872b3
commit 589b29bbdd
18 changed files with 307 additions and 20 deletions

View File

@@ -0,0 +1,36 @@
import { IManualJournalDeletingPayload } from '@/interfaces';
import events from '@/subscribers/events';
import { ValidateTransactionMatched } from '../ValidateTransactionsMatched';
import { Inject, Service } from 'typedi';
@Service()
export class ValidateMatchingOnCashflowDelete {
@Inject()
private validateNoMatchingLinkedService: ValidateTransactionMatched;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.cashflow.onTransactionDeleting,
this.validateMatchingOnCashflowDelete.bind(this)
);
}
/**
*
* @param {IManualJournalDeletingPayload}
*/
public async validateMatchingOnCashflowDelete({
tenantId,
oldManualJournal,
trx,
}: IManualJournalDeletingPayload) {
await this.validateNoMatchingLinkedService.validateTransactionNoMatchLinking(
tenantId,
'ManualJournal',
oldManualJournal.id
);
}
}

View File

@@ -0,0 +1,36 @@
import { Inject, Service } from 'typedi';
import { IExpenseEventDeletePayload } from '@/interfaces';
import events from '@/subscribers/events';
import { ValidateTransactionMatched } from '../ValidateTransactionsMatched';
@Service()
export class ValidateMatchingOnExpenseDelete {
@Inject()
private validateNoMatchingLinkedService: ValidateTransactionMatched;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.expenses.onDeleting,
this.validateMatchingOnExpenseDelete.bind(this)
);
}
/**
*
* @param {IExpenseEventDeletePayload}
*/
public async validateMatchingOnExpenseDelete({
tenantId,
oldExpense,
trx,
}: IExpenseEventDeletePayload) {
await this.validateNoMatchingLinkedService.validateTransactionNoMatchLinking(
tenantId,
'Expense',
oldExpense.id
);
}
}

View File

@@ -0,0 +1,36 @@
import { Inject, Service } from 'typedi';
import { IManualJournalDeletingPayload } from '@/interfaces';
import events from '@/subscribers/events';
import { ValidateTransactionMatched } from '../ValidateTransactionsMatched';
@Service()
export class ValidateMatchingOnManualJournalDelete {
@Inject()
private validateNoMatchingLinkedService: ValidateTransactionMatched;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.manualJournals.onDeleting,
this.validateMatchingOnManualJournalDelete.bind(this)
);
}
/**
*
* @param {IManualJournalDeletingPayload}
*/
public async validateMatchingOnManualJournalDelete({
tenantId,
oldManualJournal,
trx,
}: IManualJournalDeletingPayload) {
await this.validateNoMatchingLinkedService.validateTransactionNoMatchLinking(
tenantId,
'ManualJournal',
oldManualJournal.id
);
}
}

View File

@@ -0,0 +1,39 @@
import { Inject, Service } from 'typedi';
import {
IBillPaymentEventDeletedPayload,
IPaymentReceiveDeletedPayload,
} from '@/interfaces';
import { ValidateTransactionMatched } from '../ValidateTransactionsMatched';
import events from '@/subscribers/events';
@Service()
export class ValidateMatchingOnPaymentMadeDelete {
@Inject()
private validateNoMatchingLinkedService: ValidateTransactionMatched;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.billPayment.onDeleting,
this.validateMatchingOnPaymentMadeDelete.bind(this)
);
}
/**
*
* @param {IPaymentReceiveDeletedPayload}
*/
public async validateMatchingOnPaymentMadeDelete({
tenantId,
oldBillPayment,
trx,
}: IBillPaymentEventDeletedPayload) {
await this.validateNoMatchingLinkedService.validateTransactionNoMatchLinking(
tenantId,
'PaymentMade',
oldBillPayment.id
);
}
}

View File

@@ -0,0 +1,36 @@
import { Inject, Service } from 'typedi';
import { IPaymentReceiveDeletedPayload } from '@/interfaces';
import { ValidateTransactionMatched } from '../ValidateTransactionsMatched';
import events from '@/subscribers/events';
@Service()
export class ValidateMatchingOnPaymentReceivedDelete {
@Inject()
private validateNoMatchingLinkedService: ValidateTransactionMatched;
/**
* Constructor method.
*/
public attach(bus) {
bus.subscribe(
events.paymentReceive.onDeleting,
this.validateMatchingOnPaymentReceivedDelete.bind(this)
);
}
/**
*
* @param {IPaymentReceiveDeletedPayload}
*/
public async validateMatchingOnPaymentReceivedDelete({
tenantId,
oldPaymentReceive,
trx,
}: IPaymentReceiveDeletedPayload) {
await this.validateNoMatchingLinkedService.validateTransactionNoMatchLinking(
tenantId,
'PaymentReceive',
oldPaymentReceive.id
);
}
}