Browse Source

feat: add all sort apis to controller

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
1529df0053
  1. 3
      packages/nocodb-nest/src/app.module.ts
  2. 122
      packages/nocodb-nest/src/modules/sorts/sorts.controller.ts

3
packages/nocodb-nest/src/app.module.ts

@ -13,9 +13,10 @@ import { TablesModule } from './modules/tables/tables.module';
import { ViewsModule } from './modules/views/views.module'; import { ViewsModule } from './modules/views/views.module';
import { FiltersModule } from './modules/filters/filters.module'; import { FiltersModule } from './modules/filters/filters.module';
import { SortsModule } from './modules/sorts/sorts.module'; import { SortsModule } from './modules/sorts/sorts.module';
import { ColumnsModule } from './modules/columns/columns.module';
@Module({ @Module({
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule], imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule],
controllers: [], controllers: [],
providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware], providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware],
exports: [Connection, MetaService], exports: [Connection, MetaService],

122
packages/nocodb-nest/src/modules/sorts/sorts.controller.ts

@ -1,79 +1,79 @@
import { Controller, Get, Param } from '@nestjs/common'; import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { SortReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse'; import { PagedResponseImpl } from '../../helpers/PagedResponse';
import {
ExtractProjectIdMiddleware,
UseAclMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { SortsService } from './sorts.service'; import { SortsService } from './sorts.service';
@Controller('sorts') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class SortsController { export class SortsController {
constructor(private readonly sortsService: SortsService) {} constructor(private readonly sortsService: SortsService) {}
@Get('/api/v1/db/meta/views/:viewId/sorts/') @Get('/api/v1/db/meta/views/:viewId/sorts/')
@UseAclMiddleware({
permissionName: 'sortList',
})
async sortList(@Param('viewId') viewId: string) { async sortList(@Param('viewId') viewId: string) {
return; return new PagedResponseImpl(
new PagedResponseImpl(
await this.sortsService.sortList({ await this.sortsService.sortList({
viewId, viewId,
}), }),
); );
} }
}
/*
@Post('/api/v1/db/meta/views/:viewId/sorts/')
@UseAclMiddleware({
permissionName: 'sortCreate',
})
async sortCreate(@Param('viewId') viewId: string, @Body() body: SortReqType) {
const sort = await this.sortsService.sortCreate({
sort: body,
viewId,
});
return sort;
}
export async function sortCreate(req: Request<any, any, SortReqType>, res) { @Get('/api/v1/db/meta/sorts/:sortId')
const sort = await sortService.sortCreate({ @UseAclMiddleware({
sort: req.body, permissionName: 'sortGet',
viewId: req.params.viewId, })
}); async sortGet(@Param('sortId') sortId: string) {
res.json(sort); const sort = await this.sortsService.sortGet({
} sortId,
});
export async function sortUpdate(req, res) { return sort;
const sort = await sortService.sortUpdate({ }
sortId: req.params.sortId,
sort: req.body,
});
res.json(sort);
}
export async function sortDelete(req: Request, res: Response) { @Patch('/api/v1/db/meta/sorts/:sortId')
const sort = await sortService.sortDelete({ @UseAclMiddleware({
sortId: req.params.sortId, permissionName: 'sortUpdate',
}); })
res.json(sort); async sortUpdate(@Param('sortId') sortId: string, @Body() body: SortReqType) {
} const sort = await this.sortsService.sortUpdate({
sortId,
sort: body,
});
return sort;
}
export async function sortGet(req: Request, res: Response) { @Delete('/api/v1/db/meta/sorts/:sortId')
const sort = await sortService.sortGet({ async sortDelete(@Param('sortId') sortId: string) {
sortId: req.params.sortId, const sort = await this.sortsService.sortDelete({
}); sortId,
res.json(sort); });
return sort;
}
} }
const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/views/:viewId/sorts/',
metaApiMetrics,
ncMetaAclMw(sortCreate, 'sortCreate')
);
router.get(
'/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
ncMetaAclMw(sortGet, 'sortGet')
);
router.patch(
'/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
ncMetaAclMw(sortUpdate, 'sortUpdate')
);
router.delete(
'/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
ncMetaAclMw(sortDelete, 'sortDelete')
);
export default router;
* */

Loading…
Cancel
Save