From c953c48c39a525359b49018eb040e9218c68d2b8 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 10 Apr 2025 23:34:42 +0200 Subject: [PATCH] refactor(nestjs): export module --- .../modules/Accounts/models/Account.model.ts | 6 -- .../server/src/modules/Bills/Bills.module.ts | 5 +- .../modules/Bills/commands/BillsExportable.ts | 3 + .../modules/CreditNotes/CreditNotes.module.ts | 5 +- .../commands/CreditNotesExportable.ts | 3 + .../queries/GetCreditNotes.service.ts | 3 +- .../src/modules/Expenses/Expenses.module.ts | 4 +- .../modules/Expenses/ExpensesExportable.ts | 1 + .../src/modules/Export/Export.module.ts | 2 - .../src/modules/Export/ExportService.ts | 2 - .../decorators/ExportableModel.decorator.ts | 5 ++ .../ItemCategories/ItemCategory.module.ts | 8 +- .../server/src/modules/Items/Items.module.ts | 4 +- .../modules/Items/ItemsExportable.service.ts | 36 +++++++++ .../modules/Items/ItemsImportable.service.ts | 36 +++++++++ .../server/src/modules/Items/models/Item.ts | 7 ++ .../ManualJournals/ManualJournals.module.ts | 3 +- .../commands/ManualJournalExportable.ts | 4 + .../SaleEstimates/SaleEstimates.module.ts | 4 + .../SaleEstimates/SaleEstimatesExportable.ts | 3 + .../SaleInvoices/SaleInvoices.module.ts | 12 ++- .../commands/SaleInvoicesImportable.ts | 77 +++++++++---------- .../SaleInvoices/queries/GetSaleInvoices.ts | 11 ++- 23 files changed, 176 insertions(+), 68 deletions(-) create mode 100644 packages/server/src/modules/Items/ItemsExportable.service.ts create mode 100644 packages/server/src/modules/Items/ItemsImportable.service.ts diff --git a/packages/server/src/modules/Accounts/models/Account.model.ts b/packages/server/src/modules/Accounts/models/Account.model.ts index e7429581b..73b3503aa 100644 --- a/packages/server/src/modules/Accounts/models/Account.model.ts +++ b/packages/server/src/modules/Accounts/models/Account.model.ts @@ -6,9 +6,6 @@ import { ACCOUNT_TYPES, getAccountsSupportsMultiCurrency, } from '@/constants/accounts'; -// import { SearchableModel } from '@/modules/Search/SearchableMdel'; -// import { CustomViewBaseModel } from '@/modules/CustomViews/CustomViewBaseModel'; -// import { ModelSettings } from '@/modules/Settings/ModelSettings'; import { AccountTypesUtils } from '@/libs/accounts-utils/AccountTypesUtils'; import { PlaidItem } from '@/modules/BankingPlaid/models/PlaidItem'; import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel'; @@ -16,9 +13,6 @@ import { flatToNestedArray } from '@/utils/flat-to-nested-array'; import { ExportableModel } from '../../Export/decorators/ExportableModel.decorator'; import { AccountMeta } from './Account.meta'; import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator'; -// import AccountSettings from './Account.Settings'; -// import { DEFAULT_VIEWS } from '@/modules/Accounts/constants'; -// import { buildFilterQuery, buildSortColumnQuery } from '@/lib/ViewRolesBuilder'; @ExportableModel() @InjectModelMeta(AccountMeta) diff --git a/packages/server/src/modules/Bills/Bills.module.ts b/packages/server/src/modules/Bills/Bills.module.ts index a9f5549e1..df4d35975 100644 --- a/packages/server/src/modules/Bills/Bills.module.ts +++ b/packages/server/src/modules/Bills/Bills.module.ts @@ -27,6 +27,7 @@ import { GetBillsService } from './queries/GetBills.service'; import { DynamicListModule } from '../DynamicListing/DynamicList.module'; import { InventoryCostModule } from '../InventoryCost/InventoryCost.module'; import { BillsExportable } from './commands/BillsExportable'; +import { BillsImportable } from './commands/BillsImportable'; @Module({ imports: [ @@ -58,8 +59,10 @@ import { BillsExportable } from './commands/BillsExportable'; BillGLEntriesSubscriber, BillInventoryTransactions, BillWriteInventoryTransactionsSubscriber, - BillsExportable + BillsExportable, + BillsImportable ], controllers: [BillsController], + exports: [BillsExportable, BillsImportable], }) export class BillsModule {} diff --git a/packages/server/src/modules/Bills/commands/BillsExportable.ts b/packages/server/src/modules/Bills/commands/BillsExportable.ts index df9d09b66..832b1deed 100644 --- a/packages/server/src/modules/Bills/commands/BillsExportable.ts +++ b/packages/server/src/modules/Bills/commands/BillsExportable.ts @@ -4,8 +4,11 @@ import { Injectable } from '@nestjs/common'; import { Exportable } from '@/modules/Export/Exportable'; import { IBillsFilter } from '../Bills.types'; import { EXPORT_SIZE_LIMIT } from '@/modules/Export/constants'; +import { ExportableService } from '@/modules/Export/decorators/ExportableModel.decorator'; +import { Bill } from '../models/Bill'; @Injectable() +@ExportableService({ name: Bill.name }) export class BillsExportable extends Exportable { constructor(private readonly billsApplication: BillsApplication) { super(); diff --git a/packages/server/src/modules/CreditNotes/CreditNotes.module.ts b/packages/server/src/modules/CreditNotes/CreditNotes.module.ts index b7785488c..11d61daba 100644 --- a/packages/server/src/modules/CreditNotes/CreditNotes.module.ts +++ b/packages/server/src/modules/CreditNotes/CreditNotes.module.ts @@ -37,7 +37,7 @@ import { CreditNotesExportable } from './commands/CreditNotesExportable'; AutoIncrementOrdersModule, LedgerModule, AccountsModule, - DynamicListModule + DynamicListModule, ], providers: [ CreateCreditNoteService, @@ -54,7 +54,7 @@ import { CreditNotesExportable } from './commands/CreditNotesExportable'; CreditNoteBrandingTemplate, CreditNoteGLEntries, CreditNoteGLEntriesSubscriber, - CreditNotesExportable + CreditNotesExportable, ], exports: [ CreateCreditNoteService, @@ -68,6 +68,7 @@ import { CreditNotesExportable } from './commands/CreditNotesExportable'; GetCreditNoteState, CreditNoteApplication, CreditNoteBrandingTemplate, + CreditNotesExportable, ], controllers: [CreditNotesController], }) diff --git a/packages/server/src/modules/CreditNotes/commands/CreditNotesExportable.ts b/packages/server/src/modules/CreditNotes/commands/CreditNotesExportable.ts index ac5c8b55a..00e0dea09 100644 --- a/packages/server/src/modules/CreditNotes/commands/CreditNotesExportable.ts +++ b/packages/server/src/modules/CreditNotes/commands/CreditNotesExportable.ts @@ -2,8 +2,11 @@ import { Exportable } from '@/modules/Export/Exportable'; import { CreditNoteApplication } from '../CreditNoteApplication.service'; import { Injectable } from '@nestjs/common'; import { ICreditNotesQueryDTO } from '../types/CreditNotes.types'; +import { ExportableService } from '@/modules/Export/decorators/ExportableModel.decorator'; +import { CreditNote } from '../models/CreditNote'; @Injectable() +@ExportableService({ name: CreditNote.name }) export class CreditNotesExportable extends Exportable { constructor(private readonly creditNotesApp: CreditNoteApplication) { super(); diff --git a/packages/server/src/modules/CreditNotes/queries/GetCreditNotes.service.ts b/packages/server/src/modules/CreditNotes/queries/GetCreditNotes.service.ts index 7457c923b..a588dddad 100644 --- a/packages/server/src/modules/CreditNotes/queries/GetCreditNotes.service.ts +++ b/packages/server/src/modules/CreditNotes/queries/GetCreditNotes.service.ts @@ -1,3 +1,4 @@ +import { Inject, Injectable } from '@nestjs/common'; import * as R from 'ramda'; import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service'; import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service'; @@ -7,8 +8,6 @@ import { } from '../types/CreditNotes.types'; import { CreditNote } from '../models/CreditNote'; import { CreditNoteTransformer } from './CreditNoteTransformer'; -import { Inject } from '@nestjs/common'; -import { Injectable } from '@nestjs/common'; import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel'; @Injectable() diff --git a/packages/server/src/modules/Expenses/Expenses.module.ts b/packages/server/src/modules/Expenses/Expenses.module.ts index 60278857e..9a36478ab 100644 --- a/packages/server/src/modules/Expenses/Expenses.module.ts +++ b/packages/server/src/modules/Expenses/Expenses.module.ts @@ -23,7 +23,7 @@ import { ExpensesImportable } from './ExpensesImportable'; @Module({ imports: [LedgerModule, BranchesModule, DynamicListModule], controllers: [ExpensesController], - exports: [CreateExpense], + exports: [CreateExpense, ExpensesExportable, ExpensesImportable], providers: [ CreateExpense, ExpenseDTOTransformer, @@ -40,7 +40,7 @@ import { ExpensesImportable } from './ExpensesImportable'; ExpenseGLEntriesService, GetExpensesService, ExpensesExportable, - ExpensesImportable + ExpensesImportable, ], }) export class ExpensesModule {} diff --git a/packages/server/src/modules/Expenses/ExpensesExportable.ts b/packages/server/src/modules/Expenses/ExpensesExportable.ts index 902a2c91a..9207101ba 100644 --- a/packages/server/src/modules/Expenses/ExpensesExportable.ts +++ b/packages/server/src/modules/Expenses/ExpensesExportable.ts @@ -17,6 +17,7 @@ export class ExpensesExportable extends Exportable { /** * Retrieves the accounts data to exportable sheet. + * @param {IExpensesFilter} */ public exportable(query: IExpensesFilter) { const filterQuery = (query) => { diff --git a/packages/server/src/modules/Export/Export.module.ts b/packages/server/src/modules/Export/Export.module.ts index 59e73e771..1aec5e4f9 100644 --- a/packages/server/src/modules/Export/Export.module.ts +++ b/packages/server/src/modules/Export/Export.module.ts @@ -7,7 +7,6 @@ import { ExportApplication } from './ExportApplication'; import { ResourceModule } from '../Resource/Resource.module'; import { RegisterTenancyModel } from '../Tenancy/TenancyModels/Tenancy.module'; import { ImportModel } from '../Import/models/Import'; -import { ExportableResources } from './ExportResources'; import { ExportableRegistry } from './ExportRegistery'; import { TemplateInjectableModule } from '../TemplateInjectable/TemplateInjectable.module'; import { ChromiumlyTenancyModule } from '../ChromiumlyTenancy/ChromiumlyTenancy.module'; @@ -28,7 +27,6 @@ const models = [RegisterTenancyModel(ImportModel)]; ExportPdf, ExportAls, ExportApplication, - ExportableResources, ExportableRegistry ], exports: [...models], diff --git a/packages/server/src/modules/Export/ExportService.ts b/packages/server/src/modules/Export/ExportService.ts index 6e8e704e4..c464dd41d 100644 --- a/packages/server/src/modules/Export/ExportService.ts +++ b/packages/server/src/modules/Export/ExportService.ts @@ -3,7 +3,6 @@ import * as xlsx from 'xlsx'; import * as R from 'ramda'; import { get } from 'lodash'; import { sanitizeResourceName } from '../Import/_utils'; -import { ExportableResources } from './ExportResources'; import { Errors, ExportFormat } from './common'; import { flatDataCollections, getDataAccessor } from './utils'; import { ExportPdf } from './ExportPdf'; @@ -19,7 +18,6 @@ export class ExportResourceService { constructor( private readonly exportAls: ExportAls, private readonly exportPdf: ExportPdf, - private readonly exportableResources: ExportableResources, private readonly resourceService: ResourceService, private readonly moduleRef: ModuleRef, ) {} diff --git a/packages/server/src/modules/Export/decorators/ExportableModel.decorator.ts b/packages/server/src/modules/Export/decorators/ExportableModel.decorator.ts index 28a64e8ff..ea9ca0fb3 100644 --- a/packages/server/src/modules/Export/decorators/ExportableModel.decorator.ts +++ b/packages/server/src/modules/Export/decorators/ExportableModel.decorator.ts @@ -1,3 +1,5 @@ +import { Global } from "@nestjs/common"; + const exportableModels = new Map(); const exportableService = new Map() @@ -15,6 +17,9 @@ export function ExportableModel() { export function ExportableService({ name }: { name: string }) { return function (target: any) { exportableService.set(name, target); + + // Apply the @Global() decorator to make the service globally available + Global()(target); }; } diff --git a/packages/server/src/modules/ItemCategories/ItemCategory.module.ts b/packages/server/src/modules/ItemCategories/ItemCategory.module.ts index b9919a0ee..c5cec3989 100644 --- a/packages/server/src/modules/ItemCategories/ItemCategory.module.ts +++ b/packages/server/src/modules/ItemCategories/ItemCategory.module.ts @@ -25,10 +25,14 @@ import { ItemCategoriesImportable } from './ItemCategoriesImportable'; DeleteItemCategoryService, ItemCategoryApplication, CommandItemCategoryValidatorService, - ItemCategoriesExportable, TransformerInjectable, TenancyContext, - ItemCategoriesImportable + ItemCategoriesExportable, + ItemCategoriesImportable, + ], + exports: [ + ItemCategoriesExportable, + ItemCategoriesImportable, ], }) export class ItemCategoryModule {} diff --git a/packages/server/src/modules/Items/Items.module.ts b/packages/server/src/modules/Items/Items.module.ts index 73be6e1d1..cc0c4fb1f 100644 --- a/packages/server/src/modules/Items/Items.module.ts +++ b/packages/server/src/modules/Items/Items.module.ts @@ -16,6 +16,7 @@ import { ItemsEntriesService } from './ItemsEntries.service'; import { GetItemsService } from './GetItems.service'; import { DynamicListModule } from '../DynamicListing/DynamicList.module'; import { InventoryAdjustmentsModule } from '../InventoryAdjutments/InventoryAdjustments.module'; +import { ItemsExportable } from './ItemsExportable.service'; @Module({ imports: [ @@ -38,7 +39,8 @@ import { InventoryAdjustmentsModule } from '../InventoryAdjutments/InventoryAdju TenancyContext, TransformerInjectable, ItemsEntriesService, + ItemsExportable, ], - exports: [ItemsEntriesService], + exports: [ItemsEntriesService, ItemsExportable], }) export class ItemsModule {} diff --git a/packages/server/src/modules/Items/ItemsExportable.service.ts b/packages/server/src/modules/Items/ItemsExportable.service.ts new file mode 100644 index 000000000..6a1474bff --- /dev/null +++ b/packages/server/src/modules/Items/ItemsExportable.service.ts @@ -0,0 +1,36 @@ +import { Global, Injectable } from '@nestjs/common'; +import { Exportable } from '../Export/Exportable'; +import { EXPORT_SIZE_LIMIT } from '../Export/constants'; +import { ItemsApplicationService } from './ItemsApplication.service'; +import { IItemsFilter } from './types/Items.types'; +import { ExportableService } from '../Export/decorators/ExportableModel.decorator'; +import { Item } from './models/Item'; + +@Injectable() +@ExportableService({ name: Item.name }) +@Global() +export class ItemsExportable extends Exportable { + constructor( + private readonly itemsApplication: ItemsApplicationService, + ) { + super(); + } + + /** + * Retrieves the accounts data to exportable sheet. + * @param {IItemsFilter} query - Items export query. + */ + public exportable(query: IItemsFilter) { + const parsedQuery = { + sortOrder: 'DESC', + columnSortBy: 'created_at', + page: 1, + ...query, + pageSize: EXPORT_SIZE_LIMIT, + } as IItemsFilter; + + return this.itemsApplication + .getItems(parsedQuery) + .then((output) => output.items); + } +} \ No newline at end of file diff --git a/packages/server/src/modules/Items/ItemsImportable.service.ts b/packages/server/src/modules/Items/ItemsImportable.service.ts new file mode 100644 index 000000000..091473c87 --- /dev/null +++ b/packages/server/src/modules/Items/ItemsImportable.service.ts @@ -0,0 +1,36 @@ +import { Injectable } from '@nestjs/common'; +import { Knex } from 'knex'; +import { Importable } from '../Import/Importable'; +import { CreateItemService } from './CreateItem.service'; +import { CreateItemDto } from './dtos/Item.dto'; +import { ItemsSampleData } from './Items.constants'; + +@Injectable() +export class ItemsImportable extends Importable { + constructor( + private readonly createItemService: CreateItemService, + ) { + super(); + } + + /** + * Mapps the imported data to create a new item service. + * @param {number} tenantId + * @param {ICustomerNewDTO} createDTO + * @param {Knex.Transaction} trx + * @returns {Promise} + */ + public async importable( + createDTO: CreateItemDto, + trx?: Knex.Transaction + ): Promise { + await this.createItemService.createItem(createDTO, trx); + } + + /** + * Retrieves the sample data of customers used to download sample sheet. + */ + public sampleData(): any[] { + return ItemsSampleData; + } +} \ No newline at end of file diff --git a/packages/server/src/modules/Items/models/Item.ts b/packages/server/src/modules/Items/models/Item.ts index 39227a0e0..c9f561c81 100644 --- a/packages/server/src/modules/Items/models/Item.ts +++ b/packages/server/src/modules/Items/models/Item.ts @@ -53,6 +53,13 @@ export class Item extends TenantBaseModel { } return q; }, + + /** + * Inactive/Active mode. + */ + inactiveMode(query, active = false) { + query.where('items.active', !active); + }, }; } diff --git a/packages/server/src/modules/ManualJournals/ManualJournals.module.ts b/packages/server/src/modules/ManualJournals/ManualJournals.module.ts index 2b2a8c773..be1dabfb8 100644 --- a/packages/server/src/modules/ManualJournals/ManualJournals.module.ts +++ b/packages/server/src/modules/ManualJournals/ManualJournals.module.ts @@ -40,7 +40,8 @@ import { DynamicListModule } from '../DynamicListing/DynamicList.module'; ManualJournalGLEntries, ManualJournalWriteGLSubscriber, ManualJournalsExportable, - ManualJournalImportable + ManualJournalImportable, ], + exports: [ManualJournalsExportable, ManualJournalImportable], }) export class ManualJournalsModule {} diff --git a/packages/server/src/modules/ManualJournals/commands/ManualJournalExportable.ts b/packages/server/src/modules/ManualJournals/commands/ManualJournalExportable.ts index dc96bf0cd..1afe280d1 100644 --- a/packages/server/src/modules/ManualJournals/commands/ManualJournalExportable.ts +++ b/packages/server/src/modules/ManualJournals/commands/ManualJournalExportable.ts @@ -3,8 +3,11 @@ import { EXPORT_SIZE_LIMIT } from '../../Export/constants'; import { Injectable } from '@nestjs/common'; import { IManualJournalsFilter } from '../types/ManualJournals.types'; import { ManualJournalsApplication } from '../ManualJournalsApplication.service'; +import { ExportableService } from '@/modules/Export/decorators/ExportableModel.decorator'; +import { ManualJournal } from '../models/ManualJournal'; @Injectable() +@ExportableService({ name: ManualJournal.name }) export class ManualJournalsExportable extends Exportable { constructor( private readonly manualJournalsApplication: ManualJournalsApplication, @@ -14,6 +17,7 @@ export class ManualJournalsExportable extends Exportable { /** * Retrieves the manual journals data to exportable sheet. + * @param {IManualJournalsFilter} query - */ public exportable(query: IManualJournalsFilter) { const parsedQuery = { diff --git a/packages/server/src/modules/SaleEstimates/SaleEstimates.module.ts b/packages/server/src/modules/SaleEstimates/SaleEstimates.module.ts index 43184d0f4..2732dcac6 100644 --- a/packages/server/src/modules/SaleEstimates/SaleEstimates.module.ts +++ b/packages/server/src/modules/SaleEstimates/SaleEstimates.module.ts @@ -80,5 +80,9 @@ import { SaleEstimatesImportable } from './SaleEstimatesImportable'; SaleEstimatesExportable, SaleEstimatesImportable ], + exports: [ + SaleEstimatesExportable, + SaleEstimatesImportable + ] }) export class SaleEstimatesModule {} diff --git a/packages/server/src/modules/SaleEstimates/SaleEstimatesExportable.ts b/packages/server/src/modules/SaleEstimates/SaleEstimatesExportable.ts index 4937223fe..92fad9bcc 100644 --- a/packages/server/src/modules/SaleEstimates/SaleEstimatesExportable.ts +++ b/packages/server/src/modules/SaleEstimates/SaleEstimatesExportable.ts @@ -4,8 +4,11 @@ import { Exportable } from '../Export/Exportable'; import { ISalesInvoicesFilter } from '../SaleInvoices/SaleInvoice.types'; import { SaleEstimatesApplication } from './SaleEstimates.application'; import { ISalesEstimatesFilter } from './types/SaleEstimates.types'; +import { ExportableService } from '../Export/decorators/ExportableModel.decorator'; +import { SaleEstimate } from './models/SaleEstimate'; @Injectable() +@ExportableService({ name: SaleEstimate.name }) export class SaleEstimatesExportable extends Exportable { constructor( private readonly saleEstimatesApplication: SaleEstimatesApplication, diff --git a/packages/server/src/modules/SaleInvoices/SaleInvoices.module.ts b/packages/server/src/modules/SaleInvoices/SaleInvoices.module.ts index 3c5bcbfe3..a88679f57 100644 --- a/packages/server/src/modules/SaleInvoices/SaleInvoices.module.ts +++ b/packages/server/src/modules/SaleInvoices/SaleInvoices.module.ts @@ -57,6 +57,7 @@ import { InvoicePaymentsGLEntriesRewrite } from './InvoicePaymentsGLRewrite'; import { PaymentsReceivedModule } from '../PaymentReceived/PaymentsReceived.module'; import { SaleInvoicesCost } from './SalesInvoicesCost'; import { SaleInvoicesExportable } from './commands/SaleInvoicesExportable'; +import { SaleInvoicesImportable } from './commands/SaleInvoicesImportable'; @Module({ imports: [ @@ -119,8 +120,15 @@ import { SaleInvoicesExportable } from './commands/SaleInvoicesExportable'; SaleInvoiceWriteInventoryTransactionsSubscriber, InvoicePaymentsGLEntriesRewrite, SaleInvoicesCost, - SaleInvoicesExportable + SaleInvoicesExportable, + SaleInvoicesImportable, + ], + exports: [ + GetSaleInvoice, + SaleInvoicesCost, + SaleInvoicePdf, + SaleInvoicesExportable, + SaleInvoicesImportable, ], - exports: [GetSaleInvoice, SaleInvoicesCost, SaleInvoicePdf], }) export class SaleInvoicesModule {} diff --git a/packages/server/src/modules/SaleInvoices/commands/SaleInvoicesImportable.ts b/packages/server/src/modules/SaleInvoices/commands/SaleInvoicesImportable.ts index f0b48423c..6e4e6cee6 100644 --- a/packages/server/src/modules/SaleInvoices/commands/SaleInvoicesImportable.ts +++ b/packages/server/src/modules/SaleInvoices/commands/SaleInvoicesImportable.ts @@ -1,46 +1,39 @@ -// import { Inject, Service } from 'typedi'; -// import { Knex } from 'knex'; -// import { ISaleInvoiceCreateDTO } from '@/interfaces'; -// import { CreateSaleInvoice } from './commands/CreateSaleInvoice.service'; -// import { Importable } from '@/services/Import/Importable'; -// import { SaleInvoicesSampleData } from './constants'; +import { Injectable } from '@nestjs/common'; +import { Knex } from 'knex'; +import { CreateSaleInvoice } from './CreateSaleInvoice.service'; +import { Importable } from '@/modules/Import/Importable'; +import { CreateSaleInvoiceDto } from '../dtos/SaleInvoice.dto'; +import { SaleInvoicesSampleData } from '../constants'; -// @Service() -// export class SaleInvoicesImportable extends Importable { -// @Inject() -// private createInvoiceService: CreateSaleInvoice; +@Injectable() +export class SaleInvoicesImportable extends Importable { + constructor(private readonly createInvoiceService: CreateSaleInvoice) { + super(); + } -// /** -// * Importing to account service. -// * @param {number} tenantId -// * @param {IAccountCreateDTO} createAccountDTO -// * @returns -// */ -// public importable( -// tenantId: number, -// createAccountDTO: ISaleInvoiceCreateDTO, -// trx?: Knex.Transaction -// ) { -// return this.createInvoiceService.createSaleInvoice( -// tenantId, -// createAccountDTO, -// {}, -// trx -// ); -// } + /** + * Importing to account service. + * @param {CreateSaleInvoiceDto} createAccountDTO + */ + public importable( + createAccountDTO: CreateSaleInvoiceDto, + trx?: Knex.Transaction, + ) { + return this.createInvoiceService.createSaleInvoice(createAccountDTO, trx); + } -// /** -// * Concurrrency controlling of the importing process. -// * @returns {number} -// */ -// public get concurrency() { -// return 1; -// } + /** + * Concurrrency controlling of the importing process. + * @returns {number} + */ + public get concurrency() { + return 1; + } -// /** -// * Retrieves the sample data that used to download accounts sample sheet. -// */ -// public sampleData(): any[] { -// return SaleInvoicesSampleData; -// } -// } + /** + * Retrieves the sample data that used to download accounts sample sheet. + */ + public sampleData(): any[] { + return SaleInvoicesSampleData; + } +} diff --git a/packages/server/src/modules/SaleInvoices/queries/GetSaleInvoices.ts b/packages/server/src/modules/SaleInvoices/queries/GetSaleInvoices.ts index a7f58344e..1552df05f 100644 --- a/packages/server/src/modules/SaleInvoices/queries/GetSaleInvoices.ts +++ b/packages/server/src/modules/SaleInvoices/queries/GetSaleInvoices.ts @@ -1,18 +1,22 @@ import * as R from 'ramda'; +import { Knex } from 'knex'; +import { Inject, Injectable } from '@nestjs/common'; import { SaleInvoiceTransformer } from './SaleInvoice.transformer'; -import { Injectable } from '@nestjs/common'; import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service'; import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service'; import { IFilterMeta, IPaginationMeta } from '@/interfaces/Model'; import { SaleInvoice } from '../models/SaleInvoice'; import { ISalesInvoicesFilter } from '../SaleInvoice.types'; -import { Knex } from 'knex'; +import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel'; @Injectable() export class GetSaleInvoicesService { constructor( private readonly dynamicListService: DynamicListService, private readonly transformer: TransformerInjectable, + + @Inject(SaleInvoice.name) + private readonly saleInvoiceModel: TenantModelProxy, ) {} /** @@ -33,7 +37,8 @@ export class GetSaleInvoicesService { SaleInvoice, filter, ); - const { results, pagination } = await SaleInvoice.query() + const { results, pagination } = await this.saleInvoiceModel() + .query() .onBuild((builder) => { builder.withGraphFetched('entries.item'); builder.withGraphFetched('customer');