refactor: events tracker to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-08 11:59:55 +02:00
parent fdfb766587
commit 52362a43ab
33 changed files with 1417 additions and 10 deletions

View File

@@ -12,13 +12,15 @@ import { InventoryAdjustmentsController } from './InventoryAdjustments.controlle
import { BranchesModule } from '../Branches/Branches.module';
import { WarehousesModule } from '../Warehouses/Warehouses.module';
import { InventoryAdjustmentsGLSubscriber } from './subscribers/InventoryAdjustmentGL.subscriber';
import { InventoryAdjustmentsGLEntries } from './commands/ledger/InventoryAdjustmentsGLEntries';
import { LedgerModule } from '../Ledger/Ledger.module';
const models = [
RegisterTenancyModel(InventoryAdjustment),
RegisterTenancyModel(InventoryAdjustmentEntry),
];
@Module({
imports: [BranchesModule, WarehousesModule],
imports: [BranchesModule, WarehousesModule, LedgerModule],
controllers: [InventoryAdjustmentsController],
providers: [
...models,
@@ -29,6 +31,7 @@ const models = [
DeleteInventoryAdjustmentService,
InventoryAdjustmentsApplicationService,
InventoryAdjustmentsGLSubscriber,
InventoryAdjustmentsGLEntries,
],
exports: [...models],
})

View File

@@ -4,7 +4,6 @@ import * as R from 'ramda';
import { omit } from 'lodash';
import { events } from '@/common/events/events';
import { InventoryAdjustment } from '../models/InventoryAdjustment';
import { InventoryAdjustmentEntry } from '../models/InventoryAdjustmentEntry';
import {
IInventoryAdjustmentCreatingPayload,
IInventoryAdjustmentEventCreatedPayload,

View File

@@ -1,14 +1,13 @@
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
import { Knex } from 'knex';
import { Inject } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
import { InventoryAdjustment } from '../models/InventoryAdjustment';
import { InventoryAdjustmentEntry } from '../models/InventoryAdjustmentEntry';
import {
IInventoryAdjustmentEventPublishedPayload,
IInventoryAdjustmentPublishingPayload,
} from '../types/InventoryAdjustments.types';
import { events } from '@/common/events/events';
import { Knex } from 'knex';
import { ServiceError } from '@/modules/Items/ServiceError';
export class PublishInventoryAdjustmentService {
@@ -22,8 +21,7 @@ export class PublishInventoryAdjustmentService {
/**
* Publish the inventory adjustment transaction.
* @param {number} tenantId
* @param {number} inventoryAdjustmentId
* @param {number} inventoryAdjustmentId - Inventory adjustment ID.
*/
public async publishInventoryAdjustment(
inventoryAdjustmentId: number,

View File

@@ -13,7 +13,12 @@ export class InventoryAdjustmentsGL {
this.inventoryAdjustment = inventoryAdjustmentModel;
}
setBaseCurrency(baseCurrency: string) {
/**
* Sets the base currency.
* @param {string} baseCurrency - Base currency.
* @returns {InventoryAdjustmentsGL}
*/
public setBaseCurrency(baseCurrency: string) {
this.baseCurrency = baseCurrency;
return this;
}

View File

@@ -0,0 +1,6 @@
const ERRORS = {
INVENTORY_ADJUSTMENT_NOT_FOUND: 'INVENTORY_ADJUSTMENT_NOT_FOUND',
ITEM_SHOULD_BE_INVENTORY_TYPE: 'ITEM_SHOULD_BE_INVENTORY_TYPE',
INVENTORY_ADJUSTMENT_ALREADY_PUBLISHED:
'INVENTORY_ADJUSTMENT_ALREADY_PUBLISHED',
};