mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
refactor: split the services to multiple service classes (#202)
This commit is contained in:
@@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user