Browse Source

feat: add all filter apis to controller

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
d313bf8109
  1. 22
      packages/nocodb-nest/src/middlewares/extract-project-id/extract-project-id.middleware.ts
  2. 172
      packages/nocodb-nest/src/modules/filters/filters.controller.ts

22
packages/nocodb-nest/src/middlewares/extract-project-id/extract-project-id.middleware.ts

@ -297,3 +297,25 @@ export const UseAclMiddleware =
// UseInterceptors(ExtractProjectIdMiddleware)(target, key, descriptor);
UseInterceptors(AclMiddleware)(target, key, descriptor);
};
export const Acl =
(
permissionName: string,
{
allowedRoles,
blockApiTokenAccess,
}: {
allowedRoles?: (OrgUserRoles | string)[];
blockApiTokenAccess?: boolean;
} = {},
) =>
(target: any, key?: string, descriptor?: PropertyDescriptor) => {
SetMetadata('permission', permissionName)(target, key, descriptor);
SetMetadata('allowedRoles', allowedRoles)(target, key, descriptor);
SetMetadata('blockApiTokenAccess', blockApiTokenAccess)(
target,
key,
descriptor,
);
// UseInterceptors(ExtractProjectIdMiddleware)(target, key, descriptor);
UseInterceptors(AclMiddleware)(target, key, descriptor);
};

172
packages/nocodb-nest/src/modules/filters/filters.controller.ts

@ -1,7 +1,18 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import {
Controller,
Get,
Param,
Post,
UseGuards,
Body,
Patch,
Delete,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { FilterReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import {
Acl,
ExtractProjectIdMiddleware,
UseAclMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
@ -13,9 +24,7 @@ export class FiltersController {
constructor(private readonly filtersService: FiltersService) {}
@Get('/api/v1/db/meta/views/:viewId/filters')
@UseAclMiddleware({
permissionName: 'filterList',
})
@Acl('filterList')
async filterList(@Param('viewId') viewId: string) {
return new PagedResponseImpl(
await this.filtersService.filterList({
@ -23,105 +32,78 @@ export class FiltersController {
}),
);
}
}
/*
export async function filterGet(req: Request, res: Response) {
res.json(await filterService.filterGet({ filterId: req.params.filterId }));
}
export async function filterChildrenRead(req: Request, res: Response) {
res.json(
new PagedResponseImpl(
await filterService.filterChildrenList({
filterId: req.params.filterParentId,
})
)
);
}
export async function filterCreate(req: Request<any, any, FilterReqType>, res) {
const filter = await filterService.filterCreate({
filter: req.body,
viewId: req.params.viewId,
@Post('/api/v1/db/meta/views/:viewId/filters')
@Acl('filterCreate')
async filterCreate(
@Param('viewId') viewId: string,
@Body() body: FilterReqType,
) {
const filter = await this.filtersService.filterCreate({
filter: body,
viewId: viewId,
});
res.json(filter);
}
return filter;
}
export async function filterUpdate(req, res) {
const filter = await filterService.filterUpdate({
filterId: req.params.filterId,
filter: req.body,
@Post('/api/v1/db/meta/hooks/:hookId/filters')
@Acl('hookFilterCreate')
async hookFilterCreate(
@Param('hookId') hookId: string,
@Body() body: FilterReqType,
) {
const filter = await this.filtersService.hookFilterCreate({
filter: body,
hookId,
});
res.json(filter);
}
return filter;
}
export async function filterDelete(req: Request, res: Response) {
const filter = await filterService.filterDelete({
filterId: req.params.filterId,
});
res.json(filter);
}
@Get('/api/v1/db/meta/filters/:filterId')
@Acl('filterGet')
async filterGet(@Param('filterId') filterId: string) {
return await this.filtersService.filterGet({ filterId });
}
export async function hookFilterList(req: Request, res: Response) {
res.json(
new PagedResponseImpl(
await filterService.hookFilterList({
hookId: req.params.hookId,
})
)
@Get('/api/v1/db/meta/filters/:filterParentId/children')
@Acl('filterChildrenList')
async filterChildrenRead(filterParentId: string) {
return new PagedResponseImpl(
await this.filtersService.filterChildrenList({
filterId: filterParentId,
}),
);
}
}
export async function hookFilterCreate(
req: Request<any, any, FilterReqType>,
res
) {
const filter = await filterService.hookFilterCreate({
filter: req.body,
hookId: req.params.hookId,
@Patch('/api/v1/db/meta/filters/:filterId')
@Acl('filterUpdate')
async filterUpdate(
@Param('filterId') filterId: string,
@Body() body: FilterReqType,
) {
const filter = await this.filtersService.filterUpdate({
filterId: filterId,
filter: body,
});
res.json(filter);
}
const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/views/:viewId/filters',
metaApiMetrics,
ncMetaAclMw(filterCreate, 'filterCreate')
);
return filter;
}
router.get(
'/api/v1/db/meta/hooks/:hookId/filters',
ncMetaAclMw(hookFilterList, 'filterList')
);
router.post(
'/api/v1/db/meta/hooks/:hookId/filters',
metaApiMetrics,
ncMetaAclMw(hookFilterCreate, 'filterCreate')
);
@Delete('/api/v1/db/meta/filters/:filterId')
@Acl('filterDelete')
async filterDelete(@Param('filterId') filterId: string) {
const filter = await this.filtersService.filterDelete({
filterId,
});
return filter;
}
router.get(
'/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterGet, 'filterGet')
);
router.patch(
'/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterUpdate, 'filterUpdate')
);
router.delete(
'/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterDelete, 'filterDelete')
);
router.get(
'/api/v1/db/meta/filters/:filterParentId/children',
metaApiMetrics,
ncMetaAclMw(filterChildrenRead, 'filterChildrenRead')
);
export default router;
* */
@Get('/api/v1/db/meta/hooks/:hookId/filters')
@Acl('hookFilterList')
async hookFilterList(@Param('hookId') hookId: string) {
return new PagedResponseImpl(
await this.filtersService.hookFilterList({
hookId: hookId,
}),
);
}
}

Loading…
Cancel
Save