refactor(nestjs): export module

This commit is contained in:
Ahmed Bouhuolia
2025-04-10 23:34:42 +02:00
parent ab49113d5a
commit c953c48c39
23 changed files with 176 additions and 68 deletions

View File

@@ -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 {}

View 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);
}
}

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

View File

@@ -53,6 +53,13 @@ export class Item extends TenantBaseModel {
}
return q;
},
/**
* Inactive/Active mode.
*/
inactiveMode(query, active = false) {
query.where('items.active', !active);
},
};
}