refactor(nestjs): export module

This commit is contained in:
Ahmed Bouhuolia
2025-04-08 16:19:35 +02:00
parent 6287f8b6e3
commit 04c25bd31a
60 changed files with 748 additions and 504 deletions

View File

@@ -26,6 +26,7 @@ import { BillInventoryTransactions } from './commands/BillInventoryTransactions'
import { GetBillsService } from './queries/GetBills.service';
import { DynamicListModule } from '../DynamicListing/DynamicList.module';
import { InventoryCostModule } from '../InventoryCost/InventoryCost.module';
import { BillsExportable } from './commands/BillsExportable';
@Module({
imports: [
@@ -57,6 +58,7 @@ import { InventoryCostModule } from '../InventoryCost/InventoryCost.module';
BillGLEntriesSubscriber,
BillInventoryTransactions,
BillWriteInventoryTransactionsSubscriber,
BillsExportable
],
controllers: [BillsController],
})

View File

@@ -1,37 +1,35 @@
// import { Inject, Service } from 'typedi';
// import { Knex } from 'knex';
// import { IBillsFilter } from '@/interfaces';
// import { Exportable } from '@/services/Export/Exportable';
// import { BillsApplication } from '../Bills.application';
// import { EXPORT_SIZE_LIMIT } from '@/services/Export/constants';
// import Objection from 'objection';
import { Knex } from 'knex';
import { BillsApplication } from '../Bills.application';
import { Injectable } from '@nestjs/common';
import { Exportable } from '@/modules/Export/Exportable';
import { IBillsFilter } from '../Bills.types';
import { EXPORT_SIZE_LIMIT } from '@/modules/Export/constants';
// @Service()
// export class BillsExportable extends Exportable {
// @Inject()
// private billsApplication: BillsApplication;
@Injectable()
export class BillsExportable extends Exportable {
constructor(private readonly billsApplication: BillsApplication) {
super();
}
// /**
// * Retrieves the accounts data to exportable sheet.
// * @param {number} tenantId
// * @returns
// */
// public exportable(tenantId: number, query: IBillsFilter) {
// const filterQuery = (query) => {
// query.withGraphFetched('branch');
// query.withGraphFetched('warehouse');
// };
// const parsedQuery = {
// sortOrder: 'desc',
// columnSortBy: 'created_at',
// ...query,
// page: 1,
// pageSize: EXPORT_SIZE_LIMIT,
// filterQuery,
// } as IBillsFilter;
/**
* Retrieves the accounts data to exportable sheet.
*/
public exportable(query: IBillsFilter) {
const filterQuery = (query) => {
query.withGraphFetched('branch');
query.withGraphFetched('warehouse');
};
const parsedQuery = {
sortOrder: 'desc',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
filterQuery,
} as IBillsFilter;
// return this.billsApplication
// .getBills(tenantId, parsedQuery)
// .then((output) => output.bills);
// }
// }
return this.billsApplication
.getBills(parsedQuery)
.then((output) => output.bills);
}
}

View File

@@ -14,7 +14,9 @@ import { BillLandedCost } from '@/modules/BillLandedCosts/models/BillLandedCost'
import { DiscountType } from '@/common/types/Discount';
import type { Knex, QueryBuilder } from 'knex';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
import { ExportableModel } from '@/modules/Export/decorators/ExportableModel.decorator';
@ExportableModel()
export class Bill extends TenantBaseModel {
public amount: number;
public paymentAmount: number;

View File

@@ -13,8 +13,7 @@ export class GetBillPayments {
/**
* Retrieve the specific bill associated payment transactions.
* @param {number} billId
* @returns {}
* @param {number} billId - Bill id.
*/
public getBillPayments = async (billId: number) => {
const billsEntries = await this.billPaymentEntryModel