mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 11:20:31 +00:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { OnEvent } from '@nestjs/event-emitter';
|
|
import { events } from '@/common/events/events';
|
|
import { ValidateBranchExistance } from '../../integrations/ValidateBranchExistance';
|
|
import {
|
|
IBillCreatingPayload,
|
|
IBillEditingPayload,
|
|
} from '@/modules/Bills/Bills.types';
|
|
|
|
@Injectable()
|
|
export class BillBranchValidateSubscriber {
|
|
constructor(
|
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
|
) { }
|
|
|
|
/**
|
|
* Validate branch existance on bill creating.
|
|
* @param {IBillCreatingPayload} payload
|
|
*/
|
|
@OnEvent(events.bill.onCreating, { suppressErrors: false })
|
|
async validateBranchExistanceOnBillCreating({
|
|
billDTO,
|
|
}: IBillCreatingPayload) {
|
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
billDTO.branchId,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Validate branch existance once bill editing.
|
|
* @param {IBillEditingPayload} payload
|
|
*/
|
|
@OnEvent(events.bill.onEditing, { suppressErrors: false })
|
|
async validateBranchExistanceOnBillEditing({ billDTO }: IBillEditingPayload) {
|
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
billDTO.branchId,
|
|
);
|
|
}
|
|
}
|