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

@@ -1,11 +1,3 @@
import { Model, mixin } from 'objection';
// import TenantModel from 'models/TenantModel';
// import ModelSetting from './ModelSetting';
// import BillPaymentSettings from './BillPayment.Settings';
// import CustomViewBaseModel from './CustomViewBaseModel';
// import { DEFAULT_VIEWS } from '@/services/Sales/PaymentReceived/constants';
// import ModelSearchable from './ModelSearchable';
import { BaseModel } from '@/models/Model';
import { BillPaymentEntry } from './BillPaymentEntry';
import { Vendor } from '@/modules/Vendors/models/Vendor';
import { Document } from '@/modules/ChromiumlyTenancy/models/Document';
@@ -13,11 +5,12 @@ import { ImportableModel } from '@/modules/Import/decorators/Import.decorator';
import { ExportableModel } from '@/modules/Export/decorators/ExportableModel.decorator';
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
import { BillPaymentMeta } from './BillPayment.meta';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
@ImportableModel()
@ExportableModel()
@InjectModelMeta(BillPaymentMeta)
export class BillPayment extends BaseModel {
export class BillPayment extends TenantBaseModel {
vendorId: number;
amount: number;
currencyCode: string;

View File

@@ -35,10 +35,17 @@ export class GetCreditNotesService {
* @param {ICreditNotesQueryDTO} creditNotesQuery -
*/
public async getCreditNotesList(
creditNotesQuery: ICreditNotesQueryDTO,
filterDto: ICreditNotesQueryDTO,
): Promise<GetCreditNotesResponse> {
const _filterDto = {
sortOrder: 'desc',
columnSortBy: 'created_at',
page: 1,
pageSize: 12,
...filterDto,
};
// Parses stringified filter roles.
const filter = this.parseListFilterDTO(creditNotesQuery);
const filter = this.parseListFilterDTO(_filterDto);
// Dynamic list service.
const dynamicFilter = await this.dynamicListService.dynamicList(
@@ -52,7 +59,7 @@ export class GetCreditNotesService {
builder.withGraphFetched('customer');
dynamicFilter.buildQuery()(builder);
creditNotesQuery?.filterQuery?.(builder as any);
_filterDto?.filterQuery?.(builder as any);
})
.pagination(filter.page - 1, filter.pageSize);

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,
};
}

View File

@@ -24,6 +24,6 @@ export class ItemCategoriesExportable extends Exportable {
return this.itemCategoryApp
.getItemCategories(parsedQuery)
.then((output) => output.itemCategories);
.then((output) => output.data);
}
}

View File

@@ -43,6 +43,6 @@ export interface IItemCategoriesFilter extends IDynamicListFilter {
}
export interface GetItemCategoriesResponse {
itemCategories: ItemCategory[];
data: ItemCategory[];
// filterMeta: IFilterMeta;
}

View File

@@ -51,7 +51,7 @@ export class GetItemCategoriesService {
filter,
);
// Items categories.
const itemCategories = await this.itemCategoryModel()
const data = await this.itemCategoryModel()
.query()
.onBuild((query) => {
// Subquery to calculate sumation of associated items to the item category.
@@ -61,7 +61,6 @@ export class GetItemCategoriesService {
);
dynamicList.buildQuery()(query);
});
return { itemCategories };
return { data };
}
}

View File

@@ -96,7 +96,7 @@ export class TransactionsLockingController {
@Get('/')
@ApiOperation({ summary: 'Get all transactions locking meta' })
async getTransactionLockingMetaList() {
return await this.queryTransactionsLocking.getTransactionsLockingAll();
return await this.queryTransactionsLocking.getTransactionsLockingList();
}
@Get(':module')