Files
bigcapital/server/src/services/DynamicListing/DynamicListCustomView.ts
a.bouhuolia 9186076676 feat: optimize dynamic list service.
feat: inactive mode for accounts, items, customers and vendors services.
2021-07-29 08:46:41 +02:00

53 lines
1.4 KiB
TypeScript

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