mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
refactor(nestjs): export module
This commit is contained in:
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user