refactor(nestjs): export module

This commit is contained in:
Ahmed Bouhuolia
2025-04-08 16:19:35 +02:00
parent 6287f8b6e3
commit 04c25bd31a
60 changed files with 748 additions and 504 deletions

View File

@@ -12,6 +12,7 @@ import { CreateEditCustomerDTO } from './commands/CreateEditCustomerDTO.service'
import { CustomersController } from './Customers.controller';
import { CustomersApplication } from './CustomersApplication.service';
import { DeleteCustomer } from './commands/DeleteCustomer.service';
import { CustomersExportable } from './CustomersExportable';
@Module({
imports: [TenancyDatabaseModule],
@@ -29,7 +30,8 @@ import { DeleteCustomer } from './commands/DeleteCustomer.service';
DeleteCustomer,
TenancyContext,
TransformerInjectable,
GetCustomerService
GetCustomerService,
CustomersExportable
],
})
export class CustomersModule {}

View File

@@ -4,9 +4,10 @@ import { CreateCustomer } from './commands/CreateCustomer.service';
import { EditCustomer } from './commands/EditCustomer.service';
import { DeleteCustomer } from './commands/DeleteCustomer.service';
import { EditOpeningBalanceCustomer } from './commands/EditOpeningBalanceCustomer.service';
import { ICustomerOpeningBalanceEditDTO } from './types/Customers.types';
import { ICustomerOpeningBalanceEditDTO, ICustomersFilter } from './types/Customers.types';
import { CreateCustomerDto } from './dtos/CreateCustomer.dto';
import { EditCustomerDto } from './dtos/EditCustomer.dto';
import { GetCustomers } from './queries/GetCustomers.service';
@Injectable()
export class CustomersApplication {
@@ -16,13 +17,12 @@ export class CustomersApplication {
private editCustomerService: EditCustomer,
private deleteCustomerService: DeleteCustomer,
private editOpeningBalanceService: EditOpeningBalanceCustomer,
// private getCustomersService: GetCustomers,
private getCustomersService: GetCustomers,
) {}
/**
* Retrieves the given customer details.
* @param {number} tenantId
* @param {number} customerId
* @param {number} customerId - Customer id.
*/
public getCustomer = (customerId: number) => {
return this.getCustomerService.getCustomer(customerId);
@@ -30,7 +30,7 @@ export class CustomersApplication {
/**
* Creates a new customer.
* @param {ICustomerNewDTO} customerDTO
* @param {ICustomerNewDTO} customerDTO - Create customer dto.
* @returns {Promise<ICustomer>}
*/
public createCustomer = (customerDTO: CreateCustomerDto) => {
@@ -49,9 +49,7 @@ export class CustomersApplication {
/**
* Deletes the given customer and associated transactions.
* @param {number} tenantId
* @param {number} customerId
* @param {ISystemUser} authorizedUser
* @param {number} customerId - Customer id.
* @returns {Promise<void>}
*/
public deleteCustomer = (customerId: number) => {
@@ -60,9 +58,8 @@ export class CustomersApplication {
/**
* Changes the opening balance of the given customer.
* @param {number} tenantId
* @param {number} customerId
* @param {Date|string} openingBalanceEditDTO
* @param {number} customerId - Customer id.
* @param {Date|string} openingBalanceEditDTO - Opening balance edit dto.
* @returns {Promise<ICustomer>}
*/
public editOpeningBalance = (
@@ -77,10 +74,9 @@ export class CustomersApplication {
/**
* Retrieve customers paginated list.
* @param {number} tenantId - Tenant id.
* @param {ICustomersFilter} filter - Cusotmers filter.
*/
// public getCustomers = (filterDTO: ICustomersFilter) => {
// return this.getCustomersService.getCustomersList(filterDTO);
// };
public getCustomers = (filterDTO: ICustomersFilter) => {
return this.getCustomersService.getCustomersList(filterDTO);
};
}

View File

@@ -1,30 +1,34 @@
// import { Inject, Service } from 'typedi';
// import { IItemsFilter } from '@/interfaces';
// import { CustomersApplication } from './CustomersApplication';
// import { Exportable } from '@/services/Export/Exportable';
// import { EXPORT_SIZE_LIMIT } from '@/services/Export/constants';
import { Injectable } from '@nestjs/common';
import { CustomersApplication } from './CustomersApplication.service';
import { IItemsFilter } from '../Items/types/Items.types';
import { EXPORT_SIZE_LIMIT } from '../Export/constants';
import { Exportable } from '../Export/Exportable';
import { ICustomersFilter } from './types/Customers.types';
import { ExportableService } from '../Export/decorators/ExportableModel.decorator';
import { Customer } from './models/Customer';
// @Service()
// export class CustomersExportable extends Exportable {
// @Inject()
// private customersApplication: CustomersApplication;
@Injectable()
@ExportableService({ name: Customer.name })
export class CustomersExportable extends Exportable {
constructor(private readonly customersApplication: CustomersApplication) {
super();
}
// /**
// * Retrieves the accounts data to exportable sheet.
// * @param {number} tenantId
// * @returns
// */
// public exportable(tenantId: number, query: IItemsFilter) {
// const parsedQuery = {
// sortOrder: 'DESC',
// columnSortBy: 'created_at',
// ...query,
// page: 1,
// pageSize: EXPORT_SIZE_LIMIT,
// } as IItemsFilter;
/**
* Retrieves the accounts data to exportable sheet.
* @param {ICustomersFilter} query - Customers query.
*/
public exportable(query: ICustomersFilter) {
const parsedQuery = {
sortOrder: 'DESC',
columnSortBy: 'created_at',
...query,
page: 1,
pageSize: EXPORT_SIZE_LIMIT,
} as IItemsFilter;
// return this.customersApplication
// .getCustomers(tenantId, parsedQuery)
// .then((output) => output.customers);
// }
// }
return this.customersApplication
.getCustomers(parsedQuery)
.then((output) => output.customers);
}
}