refactor: migrate credit note and vendor credit services to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-29 18:37:33 +02:00
parent 9f9b75cd31
commit caf235e2b5
107 changed files with 7396 additions and 109 deletions

View File

@@ -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
);
};
}