refactor: import resource module to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-13 10:15:57 +02:00
parent 270b421a6c
commit 72818759a5
38 changed files with 479 additions and 424 deletions

View File

@@ -6,11 +6,16 @@ import {
Param,
Post,
Put,
Query,
} from '@nestjs/common';
import { InventoryAdjustmentsApplicationService } from './InventoryAdjustmentsApplication.service';
import { IQuickInventoryAdjustmentDTO } from './types/InventoryAdjustments.types';
import {
IInventoryAdjustmentsFilter,
IQuickInventoryAdjustmentDTO,
} from './types/InventoryAdjustments.types';
import { InventoryAdjustment } from './models/InventoryAdjustment';
import { PublicRoute } from '../Auth/Jwt.guard';
import { IPaginationMeta } from '@/interfaces/Model';
@Controller('inventory-adjustments')
@PublicRoute()
@@ -37,6 +42,18 @@ export class InventoryAdjustmentsController {
);
}
@Get()
public async getInventoryAdjustments(
@Query() filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
inventoryAdjustments: InventoryAdjustment[];
pagination: IPaginationMeta;
}> {
return this.inventoryAdjustmentsApplicationService.getInventoryAdjustments(
filterDTO,
);
}
@Get(':id')
public async getInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number,

View File

@@ -2,9 +2,14 @@ import { Injectable } from '@nestjs/common';
import { DeleteInventoryAdjustmentService } from './commands/DeleteInventoryAdjustment.service';
import { PublishInventoryAdjustmentService } from './commands/PublishInventoryAdjustment.service';
import { CreateQuickInventoryAdjustmentService } from './commands/CreateQuickInventoryAdjustment.service';
import { IQuickInventoryAdjustmentDTO } from './types/InventoryAdjustments.types';
import {
IInventoryAdjustmentsFilter,
IQuickInventoryAdjustmentDTO,
} from './types/InventoryAdjustments.types';
import { InventoryAdjustment } from './models/InventoryAdjustment';
import { GetInventoryAdjustmentService } from './queries/GetInventoryAdjustment.service';
import { GetInventoryAdjustmentsService } from './queries/GetInventoryAdjustments.service';
import { IPaginationMeta } from '@/interfaces/Model';
@Injectable()
export class InventoryAdjustmentsApplicationService {
@@ -13,6 +18,7 @@ export class InventoryAdjustmentsApplicationService {
private readonly deleteInventoryAdjustmentService: DeleteInventoryAdjustmentService,
private readonly publishInventoryAdjustmentService: PublishInventoryAdjustmentService,
private readonly getInventoryAdjustmentService: GetInventoryAdjustmentService,
private readonly getInventoryAdjustmentsService: GetInventoryAdjustmentsService,
) {}
/**
@@ -63,4 +69,19 @@ export class InventoryAdjustmentsApplicationService {
inventoryAdjustmentId,
);
}
/**
* Retrieves the inventory adjustments paginated list.
* @param {IInventoryAdjustmentsFilter} adjustmentsFilter - Inventory adjustments filter.
*/
public async getInventoryAdjustments(
filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
inventoryAdjustments: InventoryAdjustment[];
pagination: IPaginationMeta;
}> {
return this.getInventoryAdjustmentsService.getInventoryAdjustments(
filterDTO,
);
}
}

View File

@@ -1,56 +1,65 @@
// import { InventoryAdjustmentTransformer } from "../InventoryAdjustmentTransformer";
// import { InventoryAdjustment } from "../models/InventoryAdjustment";
// import { IInventoryAdjustmentsFilter } from "../types/InventoryAdjustments.types";
import { Inject } from '@nestjs/common';
import * as R from 'ramda';
import { IPaginationMeta } from '@/interfaces/Model';
import { InventoryAdjustmentTransformer } from '../InventoryAdjustmentTransformer';
import { InventoryAdjustment } from '../models/InventoryAdjustment';
import { IInventoryAdjustmentsFilter } from '../types/InventoryAdjustments.types';
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service';
// import { TransformerInjectable } from "@/modules/Transformer/TransformerInjectable.service";
export class GetInventoryAdjustmentsService {
constructor(
public readonly transformer: TransformerInjectable,
private readonly dynamicListService: DynamicListService,
// export class GetInventoryAdjustmentsService {
@Inject(InventoryAdjustment.name)
private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
) {}
/**
* Retrieve the inventory adjustments paginated list.
* @param {number} tenantId
* @param {IInventoryAdjustmentsFilter} adjustmentsFilter
*/
public async getInventoryAdjustments(
filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
inventoryAdjustments: InventoryAdjustment[];
pagination: IPaginationMeta;
}> {
// Parses inventory adjustments list filter DTO.
const filter = this.parseListFilterDTO(filterDTO);
// constructor(
// public readonly transformer: TransformerInjectable,
// private readonly inventoryAdjustmentModel: typeof InventoryAdjustment,
// ) {
// }
// /**
// * Retrieve the inventory adjustments paginated list.
// * @param {number} tenantId
// * @param {IInventoryAdjustmentsFilter} adjustmentsFilter
// */
// public async getInventoryAdjustments(
// tenantId: number,
// filterDTO: IInventoryAdjustmentsFilter,
// ): Promise<{
// inventoryAdjustments: IInventoryAdjustment[];
// pagination: IPaginationMeta;
// }> {
// Dynamic list service.
const dynamicFilter = await this.dynamicListService.dynamicList(
InventoryAdjustment,
filter,
);
const { results, pagination } = await this.inventoryAdjustmentModel
.query()
.onBuild((query) => {
query.withGraphFetched('entries.item');
query.withGraphFetched('adjustmentAccount');
// // Parses inventory adjustments list filter DTO.
// const filter = this.parseListFilterDTO(filterDTO);
dynamicFilter.buildQuery()(query);
})
.pagination(filter.page - 1, filter.pageSize);
// // Dynamic list service.
// const dynamicFilter = await this.dynamicListService.dynamicList(
// tenantId,
// InventoryAdjustment,
// filter,
// );
// const { results, pagination } = await this.inventoryAdjustmentModel.query()
// .onBuild((query) => {
// query.withGraphFetched('entries.item');
// query.withGraphFetched('adjustmentAccount');
// Retrieves the transformed inventory adjustments.
const inventoryAdjustments = await this.transformer.transform(
results,
new InventoryAdjustmentTransformer(),
);
return {
inventoryAdjustments,
pagination,
};
}
// dynamicFilter.buildQuery()(query);
// })
// .pagination(filter.page - 1, filter.pageSize);
// // Retrieves the transformed inventory adjustments.
// const inventoryAdjustments = await this.transformer.transform(
// results,
// new InventoryAdjustmentTransformer(),
// );
// return {
// inventoryAdjustments,
// pagination,
// };
// }
// }
/**
* Parses inventory adjustments list filter DTO.
* @param filterDTO -
*/
private parseListFilterDTO(filterDTO) {
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
}
}