refactor: dynamic list to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-14 22:57:54 +02:00
parent 081fdebee0
commit e7e7a95aa1
81 changed files with 596 additions and 742 deletions

View File

@@ -1,154 +0,0 @@
// import { Inject, Service } from 'typedi';
// import { omit } from 'lodash';
// import moment from 'moment';
// import * as R from 'ramda';
// import { Knex } from 'knex';
// import { ServiceError } from '@/exceptions';
// import {
// IInventoryAdjustment,
// IPaginationMeta,
// IInventoryAdjustmentsFilter,
// IInventoryTransaction,
// IInventoryAdjustmentEventPublishedPayload,
// IInventoryAdjustmentEventDeletedPayload,
// IInventoryAdjustmentDeletingPayload,
// IInventoryAdjustmentPublishingPayload,
// } from '@/interfaces';
// import events from '@/subscribers/events';
// import DynamicListingService from '@/services/DynamicListing/DynamicListService';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
// import InventoryService from './Inventory';
// import UnitOfWork from '@/services/UnitOfWork';
// import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
// import InventoryAdjustmentTransformer from './InventoryAdjustmentTransformer';
// import { BranchTransactionDTOTransform } from '@/services/Branches/Integrations/BranchTransactionDTOTransform';
// import { WarehouseTransactionDTOTransform } from '@/services/Warehouses/Integrations/WarehouseTransactionDTOTransform';
// import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
// 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',
// };
// @Service()
// export default class InventoryAdjustmentService {
// @Inject()
// private tenancy: HasTenancyService;
// @Inject()
// private eventPublisher: EventPublisher;
// @Inject()
// private inventoryService: InventoryService;
// @Inject()
// private dynamicListService: DynamicListingService;
// @Inject()
// private uow: UnitOfWork;
// @Inject()
// private branchDTOTransform: BranchTransactionDTOTransform;
// @Inject()
// private warehouseDTOTransform: WarehouseTransactionDTOTransform;
// @Inject()
// private transfromer: TransformerInjectable;
// /**
// * Retrieve the inventory adjustment or throw not found service error.
// * @param {number} tenantId -
// * @param {number} adjustmentId -
// */
// async getInventoryAdjustmentOrThrowError(
// tenantId: number,
// adjustmentId: number
// ) {
// const { InventoryAdjustment } = this.tenancy.models(tenantId);
// const inventoryAdjustment = await InventoryAdjustment.query()
// .findById(adjustmentId)
// .withGraphFetched('entries');
// if (!inventoryAdjustment) {
// throw new ServiceError(ERRORS.INVENTORY_ADJUSTMENT_NOT_FOUND);
// }
// return inventoryAdjustment;
// }
// /**
// * Parses inventory adjustments list filter DTO.
// * @param filterDTO -
// */
// private parseListFilterDTO(filterDTO) {
// return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
// }
// /**
// * Writes the inventory transactions from the inventory adjustment transaction.
// * @param {number} tenantId -
// * @param {IInventoryAdjustment} inventoryAdjustment -
// * @param {boolean} override -
// * @param {Knex.Transaction} trx -
// * @return {Promise<void>}
// */
// public async writeInventoryTransactions(
// tenantId: number,
// inventoryAdjustment: IInventoryAdjustment,
// override: boolean = false,
// trx?: Knex.Transaction
// ): Promise<void> {
// const commonTransaction = {
// direction: inventoryAdjustment.inventoryDirection,
// date: inventoryAdjustment.date,
// transactionType: 'InventoryAdjustment',
// transactionId: inventoryAdjustment.id,
// createdAt: inventoryAdjustment.createdAt,
// costAccountId: inventoryAdjustment.adjustmentAccountId,
// branchId: inventoryAdjustment.branchId,
// warehouseId: inventoryAdjustment.warehouseId,
// };
// const inventoryTransactions = [];
// inventoryAdjustment.entries.forEach((entry) => {
// inventoryTransactions.push({
// ...commonTransaction,
// itemId: entry.itemId,
// quantity: entry.quantity,
// rate: entry.cost,
// });
// });
// // Saves the given inventory transactions to the storage.
// await this.inventoryService.recordInventoryTransactions(
// tenantId,
// inventoryTransactions,
// override,
// trx
// );
// }
// /**
// * Reverts the inventory transactions from the inventory adjustment transaction.
// * @param {number} tenantId
// * @param {number} inventoryAdjustmentId
// */
// async revertInventoryTransactions(
// tenantId: number,
// inventoryAdjustmentId: number,
// trx?: Knex.Transaction
// ): Promise<{ oldInventoryTransactions: IInventoryTransaction[] }> {
// return this.inventoryService.deleteInventoryTransactions(
// tenantId,
// inventoryAdjustmentId,
// 'InventoryAdjustment',
// trx
// );
// }
// }

View File

@@ -16,8 +16,10 @@ import {
import { InventoryAdjustment } from './models/InventoryAdjustment';
import { PublicRoute } from '../Auth/Jwt.guard';
import { IPaginationMeta } from '@/interfaces/Model';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
@Controller('inventory-adjustments')
@ApiTags('inventory-adjustments')
@PublicRoute()
export class InventoryAdjustmentsController {
constructor(
@@ -25,6 +27,7 @@ export class InventoryAdjustmentsController {
) {}
@Post('quick')
@ApiOperation({ summary: 'Create a quick inventory adjustment.' })
public async createQuickInventoryAdjustment(
@Body() quickAdjustmentDTO: IQuickInventoryAdjustmentDTO,
): Promise<InventoryAdjustment> {
@@ -34,6 +37,7 @@ export class InventoryAdjustmentsController {
}
@Delete(':id')
@ApiOperation({ summary: 'Delete the given inventory adjustment.' })
public async deleteInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number,
): Promise<void> {
@@ -43,6 +47,7 @@ export class InventoryAdjustmentsController {
}
@Get()
@ApiOperation({ summary: 'Retrieves the inventory adjustments.' })
public async getInventoryAdjustments(
@Query() filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
@@ -55,6 +60,7 @@ export class InventoryAdjustmentsController {
}
@Get(':id')
@ApiOperation({ summary: 'Retrieves the inventory adjustment details.' })
public async getInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number,
): Promise<InventoryAdjustment> {
@@ -64,6 +70,7 @@ export class InventoryAdjustmentsController {
}
@Put(':id/publish')
@ApiOperation({ summary: 'Publish the given inventory adjustment.' })
public async publishInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number,
): Promise<void> {

View File

@@ -1,11 +1,8 @@
import { Model } from 'objection';
// import TenantModel from 'models/TenantModel';
// import InventoryAdjustmentSettings from './InventoryAdjustment.Settings';
// import ModelSetting from './ModelSetting';
import { BaseModel } from '@/models/Model';
import { InventoryAdjustmentEntry } from './InventoryAdjustmentEntry';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
export class InventoryAdjustment extends BaseModel {
export class InventoryAdjustment extends TenantBaseModel {
date!: string;
type!: string;
adjustmentAccountId!: number;
@@ -32,28 +29,28 @@ export class InventoryAdjustment extends BaseModel {
/**
* Timestamps columns.
*/
get timestamps() {
get timestamps(): Array<string> {
return ['created_at'];
}
/**
* Virtual attributes.
*/
static get virtualAttributes() {
static get virtualAttributes(): Array<string> {
return ['formattedType', 'inventoryDirection', 'isPublished'];
}
/**
* Retrieve formatted adjustment type.
*/
get formattedType() {
get formattedType(): string {
return InventoryAdjustment.getFormattedType(this.type);
}
/**
* Retrieve formatted reference type.
*/
get inventoryDirection() {
get inventoryDirection(): string {
return InventoryAdjustment.getInventoryDirection(this.type);
}
@@ -61,7 +58,7 @@ export class InventoryAdjustment extends BaseModel {
* Detarmines whether the adjustment is published.
* @return {boolean}
*/
get isPublished() {
get isPublished(): boolean {
return !!this.publishedAt;
}

View File

@@ -31,7 +31,7 @@ export class GetInventoryAdjustmentsService {
// Dynamic list service.
const dynamicFilter = await this.dynamicListService.dynamicList(
InventoryAdjustment,
this.inventoryAdjustmentModel,
filter,
);
const { results, pagination } = await this.inventoryAdjustmentModel