mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
42 lines
1.4 KiB
TypeScript
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,
|
|
);
|
|
}
|
|
}
|