mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { OnEvent } from '@nestjs/event-emitter';
|
|
import {
|
|
IAllocatedLandedCostCreatedPayload,
|
|
IAllocatedLandedCostDeletedPayload,
|
|
} from '../types/BillLandedCosts.types';
|
|
import { events } from '@/common/events/events';
|
|
import { LandedCostInventoryTransactions } from './LandedCostInventoryTransactions.service';
|
|
|
|
@Injectable()
|
|
export class LandedCostInventoryTransactionsSubscriber {
|
|
constructor(
|
|
private readonly landedCostInventory: LandedCostInventoryTransactions,
|
|
) {}
|
|
|
|
/**
|
|
* Writes inventory transactions of the landed cost transaction once created.
|
|
* @param {IAllocatedLandedCostCreatedPayload} payload -
|
|
*/
|
|
@OnEvent(events.billLandedCost.onCreated)
|
|
async writeInventoryTransactionsOnceCreated({
|
|
billLandedCost,
|
|
trx,
|
|
bill,
|
|
}: IAllocatedLandedCostCreatedPayload) {
|
|
// Records the inventory transactions.
|
|
await this.landedCostInventory.recordInventoryTransactions(
|
|
billLandedCost,
|
|
bill,
|
|
trx,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Reverts inventory transactions of the landed cost transaction once deleted.
|
|
* @param {IAllocatedLandedCostDeletedPayload} payload -
|
|
*/
|
|
@OnEvent(events.billLandedCost.onDeleted)
|
|
async revertInventoryTransactionsOnceDeleted({
|
|
oldBillLandedCost,
|
|
trx,
|
|
}: IAllocatedLandedCostDeletedPayload) {
|
|
// Removes the inventory transactions.
|
|
await this.landedCostInventory.removeInventoryTransactions(
|
|
oldBillLandedCost.id,
|
|
trx,
|
|
);
|
|
}
|
|
}
|