refactor: split the services to multiple service classes (#202)

This commit is contained in:
Ahmed Bouhuolia
2023-08-10 20:29:39 +02:00
committed by GitHub
parent ffef627dc3
commit 26c6ca9e36
150 changed files with 7188 additions and 5007 deletions

View File

@@ -0,0 +1,58 @@
import { Inject, Service } from 'typedi';
import events from '@/subscribers/events';
import {
ISaleInvoiceWriteoffCreatePayload,
ISaleInvoiceWrittenOffCanceledPayload,
} from '@/interfaces';
import { SaleInvoiceWriteoffGLStorage } from './SaleInvoiceWriteoffGLStorage';
@Service()
export default class SaleInvoiceWriteoffSubscriber {
@Inject()
writeGLStorage: SaleInvoiceWriteoffGLStorage;
/**
* Attaches events.
*/
public attach(bus) {
bus.subscribe(
events.saleInvoice.onWrittenoff,
this.writeJournalEntriesOnceWriteoffCreate
);
bus.subscribe(
events.saleInvoice.onWrittenoffCanceled,
this.revertJournalEntriesOnce
);
}
/**
* Write the written-off sale invoice journal entries.
* @param {ISaleInvoiceWriteoffCreatePayload}
*/
private writeJournalEntriesOnceWriteoffCreate = async ({
tenantId,
saleInvoice,
trx,
}: ISaleInvoiceWriteoffCreatePayload) => {
await this.writeGLStorage.writeInvoiceWriteoffEntries(
tenantId,
saleInvoice.id,
trx
);
};
/**
* Reverts the written-of sale invoice jounral entries.
* @param {ISaleInvoiceWrittenOffCanceledPayload}
*/
private revertJournalEntriesOnce = async ({
tenantId,
saleInvoice,
trx,
}: ISaleInvoiceWrittenOffCanceledPayload) => {
await this.writeGLStorage.revertInvoiceWriteoffEntries(
tenantId,
saleInvoice.id,
trx
);
};
}