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

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

View File

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

View File

@@ -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');