mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: optimize dynamic list service.
feat: inactive mode for accounts, items, customers and vendors services.
This commit is contained in:
52
server/src/services/DynamicListing/DynamicListCustomView.ts
Normal file
52
server/src/services/DynamicListing/DynamicListCustomView.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import DynamicListAbstruct from './DynamicListAbstruct';
|
||||
import DynamicFilterViews from 'lib/DynamicFilter/DynamicFilterViews';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import HasTenancyService from 'services/Tenancy/TenancyService';
|
||||
import {ERRORS } from './constants';
|
||||
import { IModel }from 'interfaces';
|
||||
|
||||
@Service()
|
||||
export default class DynamicListCustomView extends DynamicListAbstruct {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retreive custom view or throws error not found.
|
||||
* @param {number} tenantId
|
||||
* @param {number} viewId
|
||||
* @return {Promise<IView>}
|
||||
*/
|
||||
private getCustomViewOrThrowError = async (
|
||||
tenantId: number,
|
||||
viewId: number,
|
||||
model: IModel
|
||||
) => {
|
||||
const { viewRepository } = this.tenancy.repositories(tenantId);
|
||||
const view = await viewRepository.findOneById(viewId, 'roles');
|
||||
|
||||
if (!view || view.resourceModel !== model.name) {
|
||||
throw new ServiceError(ERRORS.VIEW_NOT_FOUND);
|
||||
}
|
||||
return view;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dynamic list custom view.
|
||||
* @param {IModel} model
|
||||
* @param {number} customViewId
|
||||
* @returns
|
||||
*/
|
||||
public dynamicListCustomView = async (
|
||||
tenantId: number,
|
||||
model,
|
||||
customViewId: number
|
||||
) => {
|
||||
const view = await this.getCustomViewOrThrowError(
|
||||
tenantId,
|
||||
customViewId,
|
||||
model
|
||||
);
|
||||
return new DynamicFilterViews(view);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user