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 { FiltersModule } from './modules/filters/filters.module';
import { SortsModule } from './modules/sorts/sorts.module';
import { ColumnsModule } from './modules/columns/columns.module';
@Module({
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule],
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule],
controllers: [],
providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware],
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 {
ExtractProjectIdMiddleware,
UseAclMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { SortsService } from './sorts.service';
@Controller('sorts')
@Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class SortsController {
constructor(private readonly sortsService: SortsService) {}
@Get('/api/v1/db/meta/views/:viewId/sorts/')
@UseAclMiddleware({
permissionName: 'sortList',
})
async sortList(@Param('viewId') viewId: string) {
return;
new PagedResponseImpl(
return new PagedResponseImpl(
await this.sortsService.sortList({
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) {
const sort = await sortService.sortCreate({
sort: req.body,
viewId: req.params.viewId,
});
res.json(sort);
}
export async function sortUpdate(req, res) {
const sort = await sortService.sortUpdate({
sortId: req.params.sortId,
sort: req.body,
});
res.json(sort);
}
@Get('/api/v1/db/meta/sorts/:sortId')
@UseAclMiddleware({
permissionName: 'sortGet',
})
async sortGet(@Param('sortId') sortId: string) {
const sort = await this.sortsService.sortGet({
sortId,
});
return sort;
}
export async function sortDelete(req: Request, res: Response) {
const sort = await sortService.sortDelete({
sortId: req.params.sortId,
});
res.json(sort);
}
@Patch('/api/v1/db/meta/sorts/:sortId')
@UseAclMiddleware({
permissionName: 'sortUpdate',
})
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) {
const sort = await sortService.sortGet({
sortId: req.params.sortId,
});
res.json(sort);
@Delete('/api/v1/db/meta/sorts/:sortId')
async sortDelete(@Param('sortId') sortId: string) {
const sort = await this.sortsService.sortDelete({
sortId,
});
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