mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: import resource module to nestjs
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user