|
|
@ -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 })); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return filter; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function filterChildrenRead(req: Request, res: Response) { |
|
|
|
@Post('/api/v1/db/meta/hooks/:hookId/filters') |
|
|
|
res.json( |
|
|
|
@Acl('hookFilterCreate') |
|
|
|
new PagedResponseImpl( |
|
|
|
async hookFilterCreate( |
|
|
|
await filterService.filterChildrenList({ |
|
|
|
@Param('hookId') hookId: string, |
|
|
|
filterId: req.params.filterParentId, |
|
|
|
@Body() body: FilterReqType, |
|
|
|
}) |
|
|
|
) { |
|
|
|
) |
|
|
|
const filter = await this.filtersService.hookFilterCreate({ |
|
|
|
); |
|
|
|
filter: body, |
|
|
|
} |
|
|
|
hookId, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return filter; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function filterCreate(req: Request<any, any, FilterReqType>, res) { |
|
|
|
@Get('/api/v1/db/meta/filters/:filterId') |
|
|
|
const filter = await filterService.filterCreate({ |
|
|
|
@Acl('filterGet') |
|
|
|
filter: req.body, |
|
|
|
async filterGet(@Param('filterId') filterId: string) { |
|
|
|
viewId: req.params.viewId, |
|
|
|
return await this.filtersService.filterGet({ filterId }); |
|
|
|
}); |
|
|
|
} |
|
|
|
res.json(filter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function filterUpdate(req, res) { |
|
|
|
@Get('/api/v1/db/meta/filters/:filterParentId/children') |
|
|
|
const filter = await filterService.filterUpdate({ |
|
|
|
@Acl('filterChildrenList') |
|
|
|
filterId: req.params.filterId, |
|
|
|
async filterChildrenRead(filterParentId: string) { |
|
|
|
filter: req.body, |
|
|
|
return new PagedResponseImpl( |
|
|
|
}); |
|
|
|
await this.filtersService.filterChildrenList({ |
|
|
|
res.json(filter); |
|
|
|
filterId: filterParentId, |
|
|
|
} |
|
|
|
}), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function filterDelete(req: Request, res: Response) { |
|
|
|
@Patch('/api/v1/db/meta/filters/:filterId') |
|
|
|
const filter = await filterService.filterDelete({ |
|
|
|
@Acl('filterUpdate') |
|
|
|
filterId: req.params.filterId, |
|
|
|
async filterUpdate( |
|
|
|
}); |
|
|
|
@Param('filterId') filterId: string, |
|
|
|
res.json(filter); |
|
|
|
@Body() body: FilterReqType, |
|
|
|
} |
|
|
|
) { |
|
|
|
|
|
|
|
const filter = await this.filtersService.filterUpdate({ |
|
|
|
|
|
|
|
filterId: filterId, |
|
|
|
|
|
|
|
filter: body, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return filter; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function hookFilterList(req: Request, res: Response) { |
|
|
|
@Delete('/api/v1/db/meta/filters/:filterId') |
|
|
|
res.json( |
|
|
|
@Acl('filterDelete') |
|
|
|
new PagedResponseImpl( |
|
|
|
async filterDelete(@Param('filterId') filterId: string) { |
|
|
|
await filterService.hookFilterList({ |
|
|
|
const filter = await this.filtersService.filterDelete({ |
|
|
|
hookId: req.params.hookId, |
|
|
|
filterId, |
|
|
|
}) |
|
|
|
}); |
|
|
|
) |
|
|
|
return filter; |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function hookFilterCreate( |
|
|
|
@Get('/api/v1/db/meta/hooks/:hookId/filters') |
|
|
|
req: Request<any, any, FilterReqType>, |
|
|
|
@Acl('hookFilterList') |
|
|
|
res |
|
|
|
async hookFilterList(@Param('hookId') hookId: string) { |
|
|
|
) { |
|
|
|
return new PagedResponseImpl( |
|
|
|
const filter = await filterService.hookFilterCreate({ |
|
|
|
await this.filtersService.hookFilterList({ |
|
|
|
filter: req.body, |
|
|
|
hookId: hookId, |
|
|
|
hookId: req.params.hookId, |
|
|
|
}), |
|
|
|
}); |
|
|
|
); |
|
|
|
res.json(filter); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const router = Router({ mergeParams: true }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.post( |
|
|
|
|
|
|
|
'/api/v1/db/meta/views/:viewId/filters', |
|
|
|
|
|
|
|
metaApiMetrics, |
|
|
|
|
|
|
|
ncMetaAclMw(filterCreate, 'filterCreate') |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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') |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
* */ |
|
|
|
|
|
|
|