mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: dynamic list to nestjs
This commit is contained in:
@@ -7,7 +7,7 @@ import { CreateCustomer } from './commands/CreateCustomer.service';
|
||||
import { CustomerValidators } from './commands/CustomerValidators.service';
|
||||
import { EditCustomer } from './commands/EditCustomer.service';
|
||||
import { EditOpeningBalanceCustomer } from './commands/EditOpeningBalanceCustomer.service';
|
||||
import { GetCustomerService } from './commands/GetCustomer.service';
|
||||
import { GetCustomerService } from './queries/GetCustomer.service';
|
||||
import { CreateEditCustomerDTO } from './commands/CreateEditCustomerDTO.service';
|
||||
import { CustomersController } from './Customers.controller';
|
||||
import { CustomersApplication } from './CustomersApplication.service';
|
||||
@@ -29,6 +29,7 @@ import { DeleteCustomer } from './commands/DeleteCustomer.service';
|
||||
DeleteCustomer,
|
||||
TenancyContext,
|
||||
TransformerInjectable,
|
||||
GetCustomerService
|
||||
],
|
||||
})
|
||||
export class CustomersModule {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { GetCustomerService } from './commands/GetCustomer.service';
|
||||
import { GetCustomerService } from './queries/GetCustomer.service';
|
||||
import { CreateCustomer } from './commands/CreateCustomer.service';
|
||||
import { EditCustomer } from './commands/EditCustomer.service';
|
||||
import { DeleteCustomer } from './commands/DeleteCustomer.service';
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
// import { Inject, Service } from 'typedi';
|
||||
// import * as R from 'ramda';
|
||||
// import {
|
||||
// ICustomer,
|
||||
// ICustomersFilter,
|
||||
// IFilterMeta,
|
||||
// IPaginationMeta,
|
||||
// } from '@/interfaces';
|
||||
// import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
// import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
||||
// import CustomerTransfromer from '../queries/CustomerTransformer';
|
||||
// import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
|
||||
// @Service()
|
||||
// export class GetCustomers {
|
||||
// @Inject()
|
||||
// private tenancy: HasTenancyService;
|
||||
|
||||
// @Inject()
|
||||
// private dynamicListService: DynamicListingService;
|
||||
|
||||
// @Inject()
|
||||
// private transformer: TransformerInjectable;
|
||||
|
||||
// /**
|
||||
// * Parses customers list filter DTO.
|
||||
// * @param filterDTO -
|
||||
// */
|
||||
// private parseCustomersListFilterDTO(filterDTO) {
|
||||
// return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Retrieve customers paginated list.
|
||||
// * @param {number} tenantId - Tenant id.
|
||||
// * @param {ICustomersFilter} filter - Cusotmers filter.
|
||||
// */
|
||||
// public async getCustomersList(
|
||||
// filterDTO: ICustomersFilter
|
||||
// ): Promise<{
|
||||
// customers: ICustomer[];
|
||||
// pagination: IPaginationMeta;
|
||||
// filterMeta: IFilterMeta;
|
||||
// }> {
|
||||
// const { Customer } = this.tenancy.models(tenantId);
|
||||
|
||||
// // Parses customers list filter DTO.
|
||||
// const filter = this.parseCustomersListFilterDTO(filterDTO);
|
||||
|
||||
// // Dynamic list.
|
||||
// const dynamicList = await this.dynamicListService.dynamicList(
|
||||
// tenantId,
|
||||
// Customer,
|
||||
// filter
|
||||
// );
|
||||
// // Customers.
|
||||
// const { results, pagination } = await Customer.query()
|
||||
// .onBuild((builder) => {
|
||||
// dynamicList.buildQuery()(builder);
|
||||
// builder.modify('inactiveMode', filter.inactiveMode);
|
||||
// })
|
||||
// .pagination(filter.page - 1, filter.pageSize);
|
||||
|
||||
// // Retrieves the transformed customers.
|
||||
// const customers = await this.transformer.transform(
|
||||
// tenantId,
|
||||
// results,
|
||||
// new CustomerTransfromer()
|
||||
// );
|
||||
// return {
|
||||
// customers,
|
||||
// pagination,
|
||||
// filterMeta: dynamicList.getResponseMeta(),
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { CustomerTransfromer } from '../queries/CustomerTransformer';
|
||||
import { CustomerTransfromer } from './CustomerTransformer';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { Customer } from '../models/Customer';
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import * as R from 'ramda';
|
||||
import { Customer } from '../models/Customer';
|
||||
import { IFilterMeta, IPaginationMeta } from '@/interfaces/Model';
|
||||
import { CustomerTransfromer } from './CustomerTransformer';
|
||||
|
||||
@Injectable()
|
||||
export class GetCustomers {
|
||||
constructor(
|
||||
private dynamicListService: DynamicListService,
|
||||
private transformer: TransformerInjectable,
|
||||
|
||||
@Inject(Customer.name) private customerModel: typeof Customer,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Parses customers list filter DTO.
|
||||
* @param filterDTO -
|
||||
*/
|
||||
private parseCustomersListFilterDTO(filterDTO) {
|
||||
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customers paginated list.
|
||||
* @param {ICustomersFilter} filter - Cusotmers filter.
|
||||
*/
|
||||
public async getCustomersList(filterDTO: ICustomersFilter): Promise<{
|
||||
customers: Customer[];
|
||||
pagination: IPaginationMeta;
|
||||
filterMeta: IFilterMeta;
|
||||
}> {
|
||||
// Parses customers list filter DTO.
|
||||
const filter = this.parseCustomersListFilterDTO(filterDTO);
|
||||
|
||||
const dynamicList = await this.dynamicListService.dynamicList(
|
||||
Customer,
|
||||
filter,
|
||||
);
|
||||
const { results, pagination } = await this.customerModel
|
||||
.query()
|
||||
.onBuild((builder) => {
|
||||
dynamicList.buildQuery()(builder);
|
||||
builder.modify('inactiveMode', filter.inactiveMode);
|
||||
})
|
||||
.pagination(filter.page - 1, filter.pageSize);
|
||||
|
||||
// Retrieves the transformed customers.
|
||||
const customers = await this.transformer.transform(
|
||||
results,
|
||||
new CustomerTransfromer(),
|
||||
);
|
||||
return {
|
||||
customers,
|
||||
pagination,
|
||||
filterMeta: dynamicList.getResponseMeta(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user