mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { IInventoryCostLotsGLEntriesWriteEvent } from '@/interfaces';
|
||||
// import { SaleReceiptCostGLEntries } from '../SaleReceiptCostGLEntries';
|
||||
|
||||
// @Service()
|
||||
// export class SaleReceiptCostGLEntriesSubscriber {
|
||||
// @Inject()
|
||||
// private saleReceiptCostEntries: SaleReceiptCostGLEntries;
|
||||
|
||||
// /**
|
||||
// * Attaches events.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(
|
||||
// events.inventory.onCostLotsGLEntriesWrite,
|
||||
// this.writeJournalEntriesOnceWriteoffCreate
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Writes the receipts cost GL entries once the inventory cost lots be written.
|
||||
// * @param {IInventoryCostLotsGLEntriesWriteEvent}
|
||||
// */
|
||||
// private writeJournalEntriesOnceWriteoffCreate = async ({
|
||||
// trx,
|
||||
// startingDate,
|
||||
// tenantId,
|
||||
// }: IInventoryCostLotsGLEntriesWriteEvent) => {
|
||||
// await this.saleReceiptCostEntries.writeInventoryCostJournalEntries(
|
||||
// tenantId,
|
||||
// startingDate,
|
||||
// trx
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
ISaleReceiptCreatedPayload,
|
||||
ISaleReceiptEditedPayload,
|
||||
ISaleReceiptEventDeletedPayload,
|
||||
} from '../types/SaleReceipts.types';
|
||||
import { SaleReceiptGLEntries } from '../ledger/SaleReceiptGLEntries';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
@Injectable()
|
||||
export class SaleReceiptGLEntriesSubscriber {
|
||||
constructor(private readonly saleReceiptGLEntries: SaleReceiptGLEntries) {}
|
||||
|
||||
/**
|
||||
* Handles writing sale receipt income journal entries once created.
|
||||
* @param {ISaleReceiptCreatedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onCreated)
|
||||
@OnEvent(events.saleReceipt.onClosed)
|
||||
public async handleWriteReceiptIncomeJournalEntrieOnCreate({
|
||||
saleReceiptId,
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptCreatedPayload) {
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
// Writes the sale receipt income journal entries.
|
||||
await this.saleReceiptGLEntries.writeIncomeGLEntries(saleReceiptId, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles sale receipt revert jouranl entries once be deleted.
|
||||
* @param {ISaleReceiptEventDeletedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onDeleted)
|
||||
public async handleRevertReceiptJournalEntriesOnDeleted({
|
||||
saleReceiptId,
|
||||
trx,
|
||||
}: ISaleReceiptEventDeletedPayload) {
|
||||
await this.saleReceiptGLEntries.revertReceiptGLEntries(saleReceiptId, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles writing sale receipt income journal entries once be edited.
|
||||
* @param {ISaleReceiptEditedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.saleReceipt.onEdited)
|
||||
public async handleWriteReceiptIncomeJournalEntrieOnEdited({
|
||||
saleReceipt,
|
||||
trx,
|
||||
}: ISaleReceiptEditedPayload) {
|
||||
// Can't continue if the sale receipt is not closed yet.
|
||||
if (!saleReceipt.closedAt) return null;
|
||||
|
||||
// Writes the sale receipt income journal entries.
|
||||
await this.saleReceiptGLEntries.rewriteReceiptGLEntries(
|
||||
saleReceipt.id,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// import { ISaleReceiptMailPresend } from '@/interfaces';
|
||||
// import events from '@/subscribers/events';
|
||||
// import { CloseSaleReceipt } from '../commands/CloseSaleReceipt.service';
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import { ServiceError } from '@/exceptions';
|
||||
// import { ERRORS } from '../constants';
|
||||
|
||||
// @Service()
|
||||
// export class SaleReceiptMarkClosedOnMailSentSubcriber {
|
||||
// @Inject()
|
||||
// private closeReceiptService: CloseSaleReceipt;
|
||||
|
||||
// /**
|
||||
// * Attaches events.
|
||||
// */
|
||||
// public attach(bus) {
|
||||
// bus.subscribe(events.saleReceipt.onPreMailSend, this.markReceiptClosed);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Marks the sale receipt closed on submitting mail.
|
||||
// * @param {ISaleReceiptMailPresend}
|
||||
// */
|
||||
// private markReceiptClosed = async ({
|
||||
// tenantId,
|
||||
// saleReceiptId,
|
||||
// messageOptions,
|
||||
// }: ISaleReceiptMailPresend) => {
|
||||
// try {
|
||||
// await this.closeReceiptService.closeSaleReceipt(tenantId, saleReceiptId);
|
||||
// } catch (error) {
|
||||
// if (
|
||||
// error instanceof ServiceError &&
|
||||
// error.errorType === ERRORS.SALE_RECEIPT_IS_ALREADY_CLOSED
|
||||
// ) {
|
||||
// } else {
|
||||
// throw error;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
Reference in New Issue
Block a user