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:
@@ -12,7 +12,7 @@ import { AccountsApplication } from './AccountsApplication.service';
|
||||
import { CreateAccountDTO } from './CreateAccount.dto';
|
||||
import { EditAccountDTO } from './EditAccount.dto';
|
||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||
import { IAccountsTransactionsFilter } from './Accounts.types';
|
||||
import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
|
||||
// import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
|
||||
// import { ZodValidationPipe } from '@/common/pipes/ZodValidation.pipe';
|
||||
|
||||
@@ -64,9 +64,9 @@ export class AccountsController {
|
||||
return this.accountsApplication.getAccount(id);
|
||||
}
|
||||
|
||||
// @Get()
|
||||
// async getAccounts(@Query() filter: IAccountsFilter) {
|
||||
// return this.accountsApplication.getAccounts(filter);
|
||||
// }
|
||||
@Get()
|
||||
async getAccounts(@Query() filter: IAccountsFilter) {
|
||||
return this.accountsApplication.getAccounts(filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,12 @@ import { TransformerInjectable } from '../Transformer/TransformerInjectable.serv
|
||||
import { ActivateAccount } from './ActivateAccount.service';
|
||||
import { GetAccountTypesService } from './GetAccountTypes.service';
|
||||
import { GetAccountTransactionsService } from './GetAccountTransactions.service';
|
||||
import { RegisterTenancyModel } from '../Tenancy/TenancyModels/Tenancy.module';
|
||||
import { BankAccount } from '../BankingTransactions/models/BankAccount';
|
||||
// import { GetAccountsService } from './GetAccounts.service';
|
||||
|
||||
const models = [RegisterTenancyModel(BankAccount)];
|
||||
|
||||
@Module({
|
||||
imports: [TenancyDatabaseModule],
|
||||
controllers: [AccountsController],
|
||||
@@ -31,10 +35,8 @@ import { GetAccountTransactionsService } from './GetAccountTransactions.service'
|
||||
ActivateAccount,
|
||||
GetAccountTypesService,
|
||||
GetAccountTransactionsService,
|
||||
...models,
|
||||
],
|
||||
exports: [
|
||||
AccountRepository,
|
||||
CreateAccountService,
|
||||
]
|
||||
exports: [AccountRepository, CreateAccountService, ...models],
|
||||
})
|
||||
export class AccountsModule {}
|
||||
|
||||
@@ -18,11 +18,11 @@ export enum IAccountsStructureType {
|
||||
}
|
||||
|
||||
// export interface IAccountsFilter extends IDynamicListFilterDTO {
|
||||
// stringifiedFilterRoles?: string;
|
||||
// onlyInactive: boolean;
|
||||
// structure?: IAccountsStructureType;
|
||||
// }
|
||||
export interface IAccountsFilter {}
|
||||
export interface IAccountsFilter {
|
||||
onlyInactive: boolean;
|
||||
structure?: IAccountsStructureType;
|
||||
}
|
||||
export interface IAccountType {
|
||||
label: string;
|
||||
key: string;
|
||||
@@ -88,7 +88,4 @@ export interface CreateAccountParams {
|
||||
ignoreUniqueName: boolean;
|
||||
}
|
||||
|
||||
|
||||
export interface IGetAccountTransactionPOJO {
|
||||
|
||||
}
|
||||
export interface IGetAccountTransactionPOJO {}
|
||||
|
||||
@@ -11,9 +11,12 @@ import { ActivateAccount } from './ActivateAccount.service';
|
||||
import { GetAccountTypesService } from './GetAccountTypes.service';
|
||||
import { GetAccountTransactionsService } from './GetAccountTransactions.service';
|
||||
import {
|
||||
IAccountsFilter,
|
||||
IAccountsTransactionsFilter,
|
||||
IGetAccountTransactionPOJO,
|
||||
} from './Accounts.types';
|
||||
import { GetAccountsService } from './GetAccounts.service';
|
||||
import { IFilterMeta } from '@/interfaces/Model';
|
||||
|
||||
@Injectable()
|
||||
export class AccountsApplication {
|
||||
@@ -24,8 +27,8 @@ export class AccountsApplication {
|
||||
private readonly activateAccountService: ActivateAccount,
|
||||
private readonly getAccountTypesService: GetAccountTypesService,
|
||||
private readonly getAccountService: GetAccount,
|
||||
// private readonly getAccountsService: GetAccounts,
|
||||
private readonly getAccountTransactionsService: GetAccountTransactionsService,
|
||||
private readonly getAccountsService: GetAccountsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -96,17 +99,16 @@ export class AccountsApplication {
|
||||
return this.getAccountTypesService.getAccountsTypes();
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Retrieves the accounts list.
|
||||
// * @param {number} tenantId
|
||||
// * @param {IAccountsFilter} filterDTO
|
||||
// * @returns {Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }>}
|
||||
// */
|
||||
// public getAccounts = (
|
||||
// filterDTO: IAccountsFilter,
|
||||
// ): Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }> => {
|
||||
// return this.getAccountsService.getAccountsList(filterDTO);
|
||||
// };
|
||||
/**
|
||||
* Retrieves the accounts list.
|
||||
* @param {IAccountsFilter} filterDTO - Filter DTO.
|
||||
* @returns {Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }>}
|
||||
*/
|
||||
public getAccounts = (
|
||||
filterDTO: IAccountsFilter,
|
||||
): Promise<{ accounts: Account[]; filterMeta: IFilterMeta }> => {
|
||||
return this.getAccountsService.getAccountsList(filterDTO);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the given account transactions.
|
||||
|
||||
@@ -1,67 +1,66 @@
|
||||
// import { Injectable } from '@nestjs/common';
|
||||
// import * as R from 'ramda';
|
||||
// import {
|
||||
// IAccountsFilter,
|
||||
// IAccountResponse,
|
||||
// IFilterMeta,
|
||||
// } from './Accounts.types';
|
||||
// import { DynamicListService } from '../DynamicListing/DynamicListService';
|
||||
// import { AccountTransformer } from './Account.transformer';
|
||||
// import { TransformerInjectable } from '../Transformer/TransformerInjectable.service';
|
||||
// import { Account } from './models/Account.model';
|
||||
// import { AccountRepository } from './repositories/Account.repository';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import * as R from 'ramda';
|
||||
import { IAccountsFilter } from './Accounts.types';
|
||||
import { DynamicListService } from '../DynamicListing/DynamicList.service';
|
||||
import { AccountTransformer } from './Account.transformer';
|
||||
import { TransformerInjectable } from '../Transformer/TransformerInjectable.service';
|
||||
import { Account } from './models/Account.model';
|
||||
import { AccountRepository } from './repositories/Account.repository';
|
||||
import { IFilterMeta } from '@/interfaces/Model';
|
||||
|
||||
// @Injectable()
|
||||
// export class GetAccountsService {
|
||||
// constructor(
|
||||
// private readonly dynamicListService: DynamicListService,
|
||||
// private readonly transformerService: TransformerInjectable,
|
||||
// private readonly accountModel: typeof Account,
|
||||
// private readonly accountRepository: AccountRepository,
|
||||
// ) {}
|
||||
@Injectable()
|
||||
export class GetAccountsService {
|
||||
constructor(
|
||||
private readonly dynamicListService: DynamicListService,
|
||||
private readonly transformerService: TransformerInjectable,
|
||||
|
||||
// /**
|
||||
// * Retrieve accounts datatable list.
|
||||
// * @param {IAccountsFilter} accountsFilter
|
||||
// * @returns {Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }>}
|
||||
// */
|
||||
// public async getAccountsList(
|
||||
// filterDTO: IAccountsFilter,
|
||||
// ): Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }> {
|
||||
// // Parses the stringified filter roles.
|
||||
// const filter = this.parseListFilterDTO(filterDTO);
|
||||
@Inject(Account.name)
|
||||
private readonly accountModel: typeof Account,
|
||||
private readonly accountRepository: AccountRepository,
|
||||
) {}
|
||||
|
||||
// // Dynamic list service.
|
||||
// const dynamicList = await this.dynamicListService.dynamicList(
|
||||
// this.accountModel,
|
||||
// filter,
|
||||
// );
|
||||
// // Retrieve accounts model based on the given query.
|
||||
// const accounts = await this.accountModel.query().onBuild((builder) => {
|
||||
// dynamicList.buildQuery()(builder);
|
||||
// builder.modify('inactiveMode', filter.inactiveMode);
|
||||
// });
|
||||
// const accountsGraph = await this.accountRepository.getDependencyGraph();
|
||||
/**
|
||||
* Retrieve accounts datatable list.
|
||||
* @param {IAccountsFilter} accountsFilter
|
||||
* @returns {Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }>}
|
||||
*/
|
||||
public async getAccountsList(
|
||||
filterDTO: IAccountsFilter,
|
||||
): Promise<{ accounts: Account[]; filterMeta: IFilterMeta }> {
|
||||
// Parses the stringified filter roles.
|
||||
const filter = this.parseListFilterDTO(filterDTO);
|
||||
|
||||
// // Retrieves the transformed accounts collection.
|
||||
// const transformedAccounts = await this.transformerService.transform(
|
||||
// accounts,
|
||||
// new AccountTransformer(),
|
||||
// { accountsGraph, structure: filterDTO.structure },
|
||||
// );
|
||||
// Dynamic list service.
|
||||
const dynamicList = await this.dynamicListService.dynamicList(
|
||||
this.accountModel,
|
||||
filter,
|
||||
);
|
||||
// Retrieve accounts model based on the given query.
|
||||
const accounts = await this.accountModel.query().onBuild((builder) => {
|
||||
dynamicList.buildQuery()(builder);
|
||||
builder.modify('inactiveMode', filter.inactiveMode);
|
||||
});
|
||||
const accountsGraph = await this.accountRepository.getDependencyGraph();
|
||||
|
||||
// return {
|
||||
// accounts: transformedAccounts,
|
||||
// filterMeta: dynamicList.getResponseMeta(),
|
||||
// };
|
||||
// }
|
||||
// Retrieves the transformed accounts collection.
|
||||
const transformedAccounts = await this.transformerService.transform(
|
||||
accounts,
|
||||
new AccountTransformer(),
|
||||
{ accountsGraph, structure: filterDTO.structure },
|
||||
);
|
||||
|
||||
// /**
|
||||
// * Parsees accounts list filter DTO.
|
||||
// * @param filterDTO
|
||||
// * @returns
|
||||
// */
|
||||
// private parseListFilterDTO(filterDTO) {
|
||||
// return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
// }
|
||||
// }
|
||||
return {
|
||||
accounts: transformedAccounts,
|
||||
filterMeta: dynamicList.getResponseMeta(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsees accounts list filter DTO.
|
||||
* @param filterDTO
|
||||
* @returns
|
||||
*/
|
||||
private parseListFilterDTO(filterDTO) {
|
||||
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user