Files
bigcapital/packages/server/src/modules/Branches/subscribers/Validators/PaymentReceiveBranchSubscriber.ts
Ahmed Bouhuolia 04d065b969 wip
2026-01-24 13:59:43 +02:00

42 lines
1.4 KiB
TypeScript

import {
IPaymentReceivedCreatingPayload,
IPaymentReceivedEditingPayload,
} from '@/modules/PaymentReceived/types/PaymentReceived.types';
import { ValidateBranchExistance } from '../../integrations/ValidateBranchExistance';
import { OnEvent } from '@nestjs/event-emitter';
import { Injectable } from '@nestjs/common';
import { events } from '@/common/events/events';
@Injectable()
export class PaymentReceiveBranchValidateSubscriber {
constructor(
private readonly validateBranchExistance: ValidateBranchExistance,
) { }
/**
* Validate branch existance on estimate creating.
* @param {IPaymentReceivedCreatingPayload} payload
*/
@OnEvent(events.paymentReceive.onCreating, { suppressErrors: false })
async validateBranchExistanceOnPaymentCreating({
paymentReceiveDTO,
}: IPaymentReceivedCreatingPayload) {
await this.validateBranchExistance.validateTransactionBranchWhenActive(
paymentReceiveDTO.branchId,
);
}
/**
* Validate branch existance once estimate editing.
* @param {IPaymentReceivedEditingPayload} payload
*/
@OnEvent(events.paymentReceive.onEditing, { suppressErrors: false })
async validateBranchExistanceOnPaymentEditing({
paymentReceiveDTO,
}: IPaymentReceivedEditingPayload) {
await this.validateBranchExistance.validateTransactionBranchWhenActive(
paymentReceiveDTO.branchId,
);
}
}