refactor: inventory adjustments e2e test cases

This commit is contained in:
Ahmed Bouhuolia
2025-01-08 15:43:43 +02:00
parent 52362a43ab
commit ee284196eb
29 changed files with 257 additions and 68 deletions

View File

@@ -1,6 +1,7 @@
import { Knex } from 'knex';
import { Inject } from '@nestjs/common';
import * as R from 'ramda';
import * as moment from 'moment';
import { omit } from 'lodash';
import { events } from '@/common/events/events';
import { InventoryAdjustment } from '../models/InventoryAdjustment';
@@ -17,6 +18,7 @@ import { Account } from '@/modules/Accounts/models/Account.model';
import { BranchTransactionDTOTransformer } from '@/modules/Branches/integrations/BranchTransactionDTOTransform';
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
import { ERRORS } from '../constants/InventoryAdjustments.constants';
export class CreateQuickInventoryAdjustmentService {
constructor(
@@ -80,7 +82,6 @@ export class CreateQuickInventoryAdjustmentService {
/**
* Creates a quick inventory adjustment for specific item.
* @param {number} tenantId - Tenant id.
* @param {IQuickInventoryAdjustmentDTO} quickAdjustmentDTO - qucik adjustment DTO.
*/
public async createQuickAdjustment(
@@ -119,7 +120,7 @@ export class CreateQuickInventoryAdjustmentService {
// Saves the inventory adjustment with associated entries to the storage.
const inventoryAdjustment = await this.inventoryAdjustmentModel
.query(trx)
.upsertGraph({
.upsertGraphAndFetch({
...invAdjustmentObject,
});
// Triggers `onInventoryAdjustmentQuickCreated` event.

View File

@@ -1,6 +1,7 @@
import { Knex } from 'knex';
import { Inject } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import * as moment from 'moment';
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
import { InventoryAdjustment } from '../models/InventoryAdjustment';
import {
@@ -9,6 +10,7 @@ import {
} from '../types/InventoryAdjustments.types';
import { events } from '@/common/events/events';
import { ServiceError } from '@/modules/Items/ServiceError';
import { ERRORS } from '../constants/InventoryAdjustments.constants';
export class PublishInventoryAdjustmentService {
constructor(
@@ -47,11 +49,15 @@ export class PublishInventoryAdjustmentService {
);
// Publish the inventory adjustment transaction.
await InventoryAdjustment.query().findById(inventoryAdjustmentId).patch({
publishedAt: moment().toMySqlDateTime(),
});
await this.inventoryAdjustmentModel
.query()
.findById(inventoryAdjustmentId)
.patch({
publishedAt: moment().toMySqlDateTime(),
});
// Retrieve the inventory adjustment after the modification.
const inventoryAdjustment = await InventoryAdjustment.query()
const inventoryAdjustment = await this.inventoryAdjustmentModel
.query()
.findById(inventoryAdjustmentId)
.withGraphFetched('entries');