mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
refactor: migrate credit note and vendor credit services to nestjs
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import RefundVendorCreditGLEntries from '../RefundVendorCredits/commands/RefundVendorCreditGLEntries';
|
||||
import {
|
||||
IRefundCreditNoteDeletedPayload,
|
||||
IRefundVendorCreditCreatedPayload,
|
||||
} from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class RefundVendorCreditGLEntriesSubscriber {
|
||||
@Inject()
|
||||
refundVendorGLEntries: RefundVendorCreditGLEntries;
|
||||
|
||||
/**
|
||||
* Attaches events with handlers.
|
||||
*/
|
||||
attach(bus) {
|
||||
bus.subscribe(
|
||||
events.vendorCredit.onRefundCreated,
|
||||
this.writeRefundVendorCreditGLEntriesOnceCreated
|
||||
);
|
||||
bus.subscribe(
|
||||
events.vendorCredit.onRefundDeleted,
|
||||
this.revertRefundVendorCreditOnceDeleted
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes refund vendor credit GL entries once the transaction created.
|
||||
* @param {IRefundCreditNoteCreatedPayload} payload -
|
||||
*/
|
||||
private writeRefundVendorCreditGLEntriesOnceCreated = async ({
|
||||
tenantId,
|
||||
trx,
|
||||
refundVendorCredit,
|
||||
}: IRefundVendorCreditCreatedPayload) => {
|
||||
await this.refundVendorGLEntries.saveRefundCreditGLEntries(
|
||||
tenantId,
|
||||
refundVendorCredit.id,
|
||||
trx
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reverts refund vendor credit GL entries once the transaction deleted.
|
||||
* @param {IRefundCreditNoteDeletedPayload} payload -
|
||||
*/
|
||||
private revertRefundVendorCreditOnceDeleted = async ({
|
||||
tenantId,
|
||||
trx,
|
||||
refundCreditId,
|
||||
}: IRefundCreditNoteDeletedPayload) => {
|
||||
await this.refundVendorGLEntries.revertRefundCreditGLEntries(
|
||||
tenantId,
|
||||
refundCreditId,
|
||||
trx
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user