refactor(nestjs): hook up the client with new endpoints

This commit is contained in:
Ahmed Bouhuolia
2025-05-14 21:45:13 +02:00
parent aef208b9d8
commit ecb80b2cf2
25 changed files with 267 additions and 166 deletions

View File

@@ -58,10 +58,7 @@ export class InventoryAdjustmentsController {
})
public async getInventoryAdjustments(
@Query() filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
inventoryAdjustments: InventoryAdjustment[];
pagination: IPaginationMeta;
}> {
) {
return this.inventoryAdjustmentsApplicationService.getInventoryAdjustments(
filterDTO,
);

View File

@@ -75,12 +75,7 @@ export class InventoryAdjustmentsApplicationService {
* Retrieves the inventory adjustments paginated list.
* @param {IInventoryAdjustmentsFilter} adjustmentsFilter - Inventory adjustments filter.
*/
public async getInventoryAdjustments(
filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
inventoryAdjustments: InventoryAdjustment[];
pagination: IPaginationMeta;
}> {
public async getInventoryAdjustments(filterDTO: IInventoryAdjustmentsFilter) {
return this.getInventoryAdjustmentsService.getInventoryAdjustments(
filterDTO,
);

View File

@@ -0,0 +1,107 @@
export const InventoryAdjustmentMeta = {
defaultFilterField: 'date',
defaultSort: {
sortOrder: 'DESC',
sortField: 'date',
},
columns: {
date: {
name: 'inventory_adjustment.field.date',
column: 'date',
fieldType: 'date',
exportable: true,
},
type: {
name: 'inventory_adjustment.field.type',
column: 'type',
fieldType: 'enumeration',
options: [
{ key: 'increment', name: 'inventory_adjustment.field.type.increment' },
{ key: 'decrement', name: 'inventory_adjustment.field.type.decrement' },
],
exportable: true,
},
adjustmentAccount: {
name: 'inventory_adjustment.field.adjustment_account',
type: 'adjustment_account_id',
exportable: true,
},
reason: {
name: 'inventory_adjustment.field.reason',
type: 'text',
exportable: true,
},
referenceNo: {
name: 'inventory_adjustment.field.reference_no',
type: 'text',
exportable: true,
},
description: {
name: 'inventory_adjustment.field.description',
type: 'text',
exportable: true,
},
publishedAt: {
name: 'inventory_adjustment.field.published_at',
type: 'date',
exportable: true,
},
createdAt: {
name: 'inventory_adjustment.field.created_at',
type: 'date',
exportable: true,
},
},
fields: {
date: {
name: 'inventory_adjustment.field.date',
column: 'date',
fieldType: 'date',
},
type: {
name: 'inventory_adjustment.field.type',
column: 'type',
fieldType: 'enumeration',
options: [
{ key: 'increment', name: 'inventory_adjustment.field.type.increment' },
{ key: 'decrement', name: 'inventory_adjustment.field.type.decrement' },
],
},
adjustment_account: {
name: 'inventory_adjustment.field.adjustment_account',
column: 'adjustment_account_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'adjustmentAccount',
relationEntityLabel: 'name',
relationEntityKey: 'slug',
},
reason: {
name: 'inventory_adjustment.field.reason',
column: 'reason',
fieldType: 'text',
},
reference_no: {
name: 'inventory_adjustment.field.reference_no',
column: 'reference_no',
fieldType: 'text',
},
description: {
name: 'inventory_adjustment.field.description',
column: 'description',
fieldType: 'text',
},
published_at: {
name: 'inventory_adjustment.field.published_at',
column: 'published_at',
fieldType: 'date',
},
created_at: {
name: 'inventory_adjustment.field.created_at',
column: 'created_at',
fieldType: 'date',
},
},
};

View File

@@ -1,7 +1,10 @@
import { Model } from 'objection';
import { InventoryAdjustmentEntry } from './InventoryAdjustmentEntry';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
import { InventoryAdjustmentMeta } from './InventoryAdjustment.meta';
@InjectModelMeta(InventoryAdjustmentMeta)
export class InventoryAdjustment extends TenantBaseModel {
public readonly date!: string;
public readonly type!: string;
@@ -16,7 +19,6 @@ export class InventoryAdjustment extends TenantBaseModel {
public readonly warehouseId!: number;
public readonly createdAt!: Date | string;
public readonly entries: InventoryAdjustmentEntry[];
/**
@@ -116,11 +118,4 @@ export class InventoryAdjustment extends TenantBaseModel {
},
};
}
/**
* Model settings.
*/
// static get meta() {
// return InventoryAdjustmentSettings;
// }
}

View File

@@ -7,6 +7,7 @@ import { IInventoryAdjustmentsFilter } from '../types/InventoryAdjustments.types
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { ISortOrder } from '@/modules/DynamicListing/DynamicFilter/DynamicFilter.types';
@Injectable()
export class GetInventoryAdjustmentsService {
@@ -27,17 +28,25 @@ export class GetInventoryAdjustmentsService {
public async getInventoryAdjustments(
filterDTO: IInventoryAdjustmentsFilter,
): Promise<{
inventoryAdjustments: InventoryAdjustment[];
data: InventoryAdjustment[];
pagination: IPaginationMeta;
}> {
const parsedFilterDto = {
sortOrder: ISortOrder.DESC,
columnSortBy: 'created_at',
page: 1,
pageSize: 12,
...filterDTO,
};
// Parses inventory adjustments list filter DTO.
const filter = this.parseListFilterDTO(filterDTO);
const filter = this.parseListFilterDTO(parsedFilterDto);
// Dynamic list service.
const dynamicFilter = await this.dynamicListService.dynamicList(
this.inventoryAdjustmentModel(),
filter,
);
const { results, pagination } = await this.inventoryAdjustmentModel()
.query()
.onBuild((query) => {
@@ -49,12 +58,12 @@ export class GetInventoryAdjustmentsService {
.pagination(filter.page - 1, filter.pageSize);
// Retrieves the transformed inventory adjustments.
const inventoryAdjustments = await this.transformer.transform(
const data = await this.transformer.transform(
results,
new InventoryAdjustmentTransformer(),
);
return {
inventoryAdjustments,
data,
pagination,
};
}