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