fix: resource advanced view filter.

This commit is contained in:
Ahmed Bouhuolia
2020-09-16 21:41:09 +02:00
parent a22c8395f3
commit ca92c925a9
72 changed files with 997 additions and 2324 deletions

View File

@@ -0,0 +1,40 @@
import { View } from 'models';
import TenantRepository from 'repositories/TenantRepository';
export default class ViewRepository extends TenantRepository {
models: any;
cache: any;
repositories: any;
/**
* Constructor method.
* @param {number} tenantId - The given tenant id.
*/
constructor(
tenantId: number,
) {
super(tenantId);
this.models = this.tenancy.models(tenantId);
this.cache = this.tenancy.cache(tenantId);
this.repositories = this.tenancy.cache(tenantId);
}
/**
* Retrieve view model by the given id.
* @param {number} id -
*/
getById(id: number) {
const { View } = this.models;
return this.cache.get(`customView.id.${id}`, () => {
return View.query().findById(id);
});
}
allByResource() {
const resourceId = 1;
return this.cache.get(`customView.resource.id.${resourceId}`, () => {
return View.query().where('resource_id', resourceId);
});
}
}