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,33 @@
import { ServiceError } from '@/exceptions';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Inject, Service } from 'typedi';
import { ERRORS } from './types';
@Service()
export class ValidateTransactionMatched {
@Inject()
private tenancy: HasTenancyService;
/**
*
* @param {number} tenantId
* @param {string} referenceType
* @param {number} referenceId
*/
public async validateTransactionNoMatchLinking(
tenantId: number,
referenceType: string,
referenceId: number
) {
const { MatchedBankTransaction } = this.tenancy.models(tenantId);
const foundMatchedTransaction =
await MatchedBankTransaction.query().findOne({
referenceType,
referenceId,
});
if (foundMatchedTransaction) {
throw new ServiceError(ERRORS.CANNOT_DELETE_TRANSACTION_MATCHED);
}
}
}