mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
refactor(nestjs): export module
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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],
|
||||
})
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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,
|
||||
) {}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Global } from "@nestjs/common";
|
||||
|
||||
const exportableModels = new Map<string, boolean>();
|
||||
const exportableService = new Map<string, any>()
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,14 @@ import { ItemCategoriesImportable } from './ItemCategoriesImportable';
|
||||
DeleteItemCategoryService,
|
||||
ItemCategoryApplication,
|
||||
CommandItemCategoryValidatorService,
|
||||
ItemCategoriesExportable,
|
||||
TransformerInjectable,
|
||||
TenancyContext,
|
||||
ItemCategoriesImportable
|
||||
ItemCategoriesExportable,
|
||||
ItemCategoriesImportable,
|
||||
],
|
||||
exports: [
|
||||
ItemCategoriesExportable,
|
||||
ItemCategoriesImportable,
|
||||
],
|
||||
})
|
||||
export class ItemCategoryModule {}
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
36
packages/server/src/modules/Items/ItemsExportable.service.ts
Normal file
36
packages/server/src/modules/Items/ItemsExportable.service.ts
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
36
packages/server/src/modules/Items/ItemsImportable.service.ts
Normal file
36
packages/server/src/modules/Items/ItemsImportable.service.ts
Normal file
@@ -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<void>}
|
||||
*/
|
||||
public async importable(
|
||||
createDTO: CreateItemDto,
|
||||
trx?: Knex.Transaction<any, any[]>
|
||||
): Promise<void> {
|
||||
await this.createItemService.createItem(createDTO, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sample data of customers used to download sample sheet.
|
||||
*/
|
||||
public sampleData(): any[] {
|
||||
return ItemsSampleData;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,13 @@ export class Item extends TenantBaseModel {
|
||||
}
|
||||
return q;
|
||||
},
|
||||
|
||||
/**
|
||||
* Inactive/Active mode.
|
||||
*/
|
||||
inactiveMode(query, active = false) {
|
||||
query.where('items.active', !active);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ import { DynamicListModule } from '../DynamicListing/DynamicList.module';
|
||||
ManualJournalGLEntries,
|
||||
ManualJournalWriteGLSubscriber,
|
||||
ManualJournalsExportable,
|
||||
ManualJournalImportable
|
||||
ManualJournalImportable,
|
||||
],
|
||||
exports: [ManualJournalsExportable, ManualJournalImportable],
|
||||
})
|
||||
export class ManualJournalsModule {}
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -80,5 +80,9 @@ import { SaleEstimatesImportable } from './SaleEstimatesImportable';
|
||||
SaleEstimatesExportable,
|
||||
SaleEstimatesImportable
|
||||
],
|
||||
exports: [
|
||||
SaleEstimatesExportable,
|
||||
SaleEstimatesImportable
|
||||
]
|
||||
})
|
||||
export class SaleEstimatesModule {}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<typeof SaleInvoice>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user