mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
IBillCreatedPayload,
|
||||
IBillEditedPayload,
|
||||
IBIllEventDeletedPayload,
|
||||
IBillOpenedPayload,
|
||||
} from '../Bills.types';
|
||||
import { BillGLEntries } from '../commands/BillsGLEntries';
|
||||
import { events } from '@/common/events/events';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
@Injectable()
|
||||
export class BillGLEntriesSubscriber {
|
||||
/**
|
||||
* @param {BillGLEntries} billGLEntries - Bill GL entries command.
|
||||
*/
|
||||
constructor(private billGLEntries: BillGLEntries) {}
|
||||
|
||||
/**
|
||||
* Handles writing journal entries once bill created.
|
||||
* @param {IBillCreatedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onCreated)
|
||||
@OnEvent(events.bill.onOpened)
|
||||
public async handlerWriteJournalEntriesOnCreate({
|
||||
bill,
|
||||
trx,
|
||||
}: IBillCreatedPayload | IBillOpenedPayload) {
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billGLEntries.writeBillGLEntries(bill.id, trx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the overwriting journal entries once bill edited.
|
||||
* @param {IBillEditedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onEdited)
|
||||
public async handleOverwriteJournalEntriesOnEdit({
|
||||
bill,
|
||||
trx,
|
||||
}: IBillEditedPayload) {
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billGLEntries.rewriteBillGLEntries(bill.id, trx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles revert journal entries on bill deleted.
|
||||
* @param {IBIllEventDeletedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onDeleted)
|
||||
public async handlerDeleteJournalEntries({
|
||||
oldBill,
|
||||
trx,
|
||||
}: IBIllEventDeletedPayload) {
|
||||
await this.billGLEntries.revertBillGLEntries(oldBill.id, trx);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
IBillCreatedPayload,
|
||||
IBillEditedPayload,
|
||||
IBIllEventDeletedPayload,
|
||||
IBillOpenedPayload,
|
||||
} from '../Bills.types';
|
||||
import { BillInventoryTransactions } from '../commands/BillInventoryTransactions';
|
||||
import { events } from '@/common/events/events';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
@Injectable()
|
||||
export class BillWriteInventoryTransactionsSubscriber {
|
||||
constructor(private readonly billsInventory: BillInventoryTransactions) {}
|
||||
|
||||
/**
|
||||
* Handles writing the inventory transactions once bill created.
|
||||
* @param {IBillCreatedPayload | IBillOpenedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onCreated)
|
||||
@OnEvent(events.bill.onOpened)
|
||||
public async handleWritingInventoryTransactions({
|
||||
bill,
|
||||
trx,
|
||||
}: IBillCreatedPayload | IBillOpenedPayload) {
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsInventory.recordInventoryTransactions(bill.id, false, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the overwriting the inventory transactions once bill edited.
|
||||
* @param {IBillEditedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onEdited)
|
||||
public async handleOverwritingInventoryTransactions({
|
||||
bill,
|
||||
trx,
|
||||
}: IBillEditedPayload) {
|
||||
// Can't continue if the bill is not opened yet.
|
||||
if (!bill.openedAt) return null;
|
||||
|
||||
await this.billsInventory.recordInventoryTransactions(bill.id, true, trx);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the reverting the inventory transactions once the bill deleted.
|
||||
* @param {IBIllEventDeletedPayload} payload -
|
||||
*/
|
||||
@OnEvent(events.bill.onDeleted)
|
||||
public async handleRevertInventoryTransactions({
|
||||
billId,
|
||||
trx,
|
||||
}: IBIllEventDeletedPayload) {
|
||||
await this.billsInventory.revertInventoryTransactions(billId, trx);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user