refactor: dynamic list to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-12 18:22:48 +02:00
parent ddaea20d16
commit 270b421a6c
117 changed files with 4232 additions and 1493 deletions

View File

@@ -0,0 +1,46 @@
import { Injectable } from '@nestjs/common';
import { ERRORS } from './constants';
import { DynamicFilterViews } from './DynamicFilter';
import { ServiceError } from '../Items/ServiceError';
import { BaseModel } from '@/models/Model';
import { DynamicListServiceAbstract } from './DynamicListServiceAbstract';
@Injectable()
export class DynamicListCustomView extends DynamicListServiceAbstract {
/**
* Retreive custom view or throws error not found.
* @param {number} tenantId
* @param {number} viewId
* @return {Promise<IView>}
*/
private getCustomViewOrThrowError = async (
viewSlug: string,
model: BaseModel,
) => {
// Finds the default view by the given view slug.
const defaultView = model.getDefaultViewBySlug(viewSlug);
if (!defaultView) {
throw new ServiceError(ERRORS.VIEW_NOT_FOUND);
}
return defaultView;
};
/**
* Dynamic list custom view.
* @param {IModel} model
* @param {number} customViewId
* @returns {DynamicFilterRoleAbstractor}
*/
public dynamicListCustomView = async (
dynamicFilter: any,
customViewSlug: string,
) => {
const model = dynamicFilter.getModel();
// Retrieve the custom view or throw not found.
const view = await this.getCustomViewOrThrowError(customViewSlug, model);
return new DynamicFilterViews(view);
};
}