mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: inventory adjustments e2e test cases
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import { Body, Controller, Delete, Param, Post } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { InventoryAdjustmentsApplicationService } from './InventoryAdjustmentsApplication.service';
|
||||
import { IQuickInventoryAdjustmentDTO } from './types/InventoryAdjustments.types';
|
||||
import { InventoryAdjustment } from './models/InventoryAdjustment';
|
||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||
|
||||
@Controller('inventory-adjustments')
|
||||
@PublicRoute()
|
||||
export class InventoryAdjustmentsController {
|
||||
constructor(
|
||||
private readonly inventoryAdjustmentsApplicationService: InventoryAdjustmentsApplicationService,
|
||||
@@ -27,7 +37,16 @@ export class InventoryAdjustmentsController {
|
||||
);
|
||||
}
|
||||
|
||||
@Post(':id/publish')
|
||||
@Get(':id')
|
||||
public async getInventoryAdjustment(
|
||||
@Param('id') inventoryAdjustmentId: number,
|
||||
): Promise<InventoryAdjustment> {
|
||||
return this.inventoryAdjustmentsApplicationService.getInventoryAdjustment(
|
||||
inventoryAdjustmentId,
|
||||
);
|
||||
}
|
||||
|
||||
@Put(':id/publish')
|
||||
public async publishInventoryAdjustment(
|
||||
@Param('id') inventoryAdjustmentId: number,
|
||||
): Promise<void> {
|
||||
|
||||
@@ -14,6 +14,7 @@ import { WarehousesModule } from '../Warehouses/Warehouses.module';
|
||||
import { InventoryAdjustmentsGLSubscriber } from './subscribers/InventoryAdjustmentGL.subscriber';
|
||||
import { InventoryAdjustmentsGLEntries } from './commands/ledger/InventoryAdjustmentsGLEntries';
|
||||
import { LedgerModule } from '../Ledger/Ledger.module';
|
||||
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
||||
|
||||
const models = [
|
||||
RegisterTenancyModel(InventoryAdjustment),
|
||||
@@ -32,6 +33,7 @@ const models = [
|
||||
InventoryAdjustmentsApplicationService,
|
||||
InventoryAdjustmentsGLSubscriber,
|
||||
InventoryAdjustmentsGLEntries,
|
||||
TenancyContext,
|
||||
],
|
||||
exports: [...models],
|
||||
})
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const ERRORS = {
|
||||
export const ERRORS = {
|
||||
INVENTORY_ADJUSTMENT_NOT_FOUND: 'INVENTORY_ADJUSTMENT_NOT_FOUND',
|
||||
ITEM_SHOULD_BE_INVENTORY_TYPE: 'ITEM_SHOULD_BE_INVENTORY_TYPE',
|
||||
INVENTORY_ADJUSTMENT_ALREADY_PUBLISHED:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Model, mixin } from 'objection';
|
||||
import { Model } from 'objection';
|
||||
// import TenantModel from 'models/TenantModel';
|
||||
// import InventoryAdjustmentSettings from './InventoryAdjustment.Settings';
|
||||
// import ModelSetting from './ModelSetting';
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
import { TransformerInjectable } from "@/modules/Transformer/TransformerInjectable.service";
|
||||
import { InventoryAdjustment } from "../models/InventoryAdjustment";
|
||||
import { InventoryAdjustmentTransformer } from "../InventoryAdjustmentTransformer";
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { InventoryAdjustment } from '../models/InventoryAdjustment';
|
||||
import { InventoryAdjustmentTransformer } from '../InventoryAdjustmentTransformer';
|
||||
import { Inject } from '@nestjs/common';
|
||||
|
||||
export class GetInventoryAdjustmentService {
|
||||
constructor(
|
||||
private readonly transformer: TransformerInjectable,
|
||||
|
||||
@Inject(InventoryAdjustment.name)
|
||||
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieve specific inventory adjustment transaction details.
|
||||
* @param {number} inventoryAdjustmentId - Inventory adjustment id.
|
||||
*/
|
||||
async getInventoryAdjustment(
|
||||
inventoryAdjustmentId: number,
|
||||
) {
|
||||
async getInventoryAdjustment(inventoryAdjustmentId: number) {
|
||||
// Retrieve inventory adjustment transation with associated models.
|
||||
const inventoryAdjustment = await InventoryAdjustment.query()
|
||||
const inventoryAdjustment = await this.inventoryAdjustmentModel
|
||||
.query()
|
||||
.findById(inventoryAdjustmentId)
|
||||
.withGraphFetched('entries.item')
|
||||
.withGraphFetched('adjustmentAccount')
|
||||
|
||||
Reference in New Issue
Block a user