mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-10 18:01:59 +00:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 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 { ICreditNoteEditingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
|
import { ICreditNoteCreatingPayload } from '@/modules/CreditNotes/types/CreditNotes.types';
|
|
|
|
@Injectable()
|
|
export class CreditNoteBranchValidateSubscriber {
|
|
constructor(
|
|
private readonly validateBranchExistance: ValidateBranchExistance,
|
|
) { }
|
|
|
|
/**
|
|
* Validate branch existance on credit note creating.
|
|
* @param {ICreditNoteCreatingPayload} payload
|
|
*/
|
|
@OnEvent(events.creditNote.onCreating)
|
|
async validateBranchExistanceOnCreditCreating({
|
|
creditNoteDTO,
|
|
}: ICreditNoteCreatingPayload) {
|
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
creditNoteDTO.branchId,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Validate branch existance once credit note editing.
|
|
* @param {ICreditNoteEditingPayload} payload
|
|
*/
|
|
@OnEvent(events.creditNote.onEditing)
|
|
async validateBranchExistanceOnCreditEditing({
|
|
creditNoteEditDTO,
|
|
}: ICreditNoteEditingPayload) {
|
|
await this.validateBranchExistance.validateTransactionBranchWhenActive(
|
|
creditNoteEditDTO.branchId,
|
|
);
|
|
}
|
|
}
|