From 1288f651d8386b58d498e50f8779a96758696c85 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:15:46 +0000 Subject: [PATCH] feat(nocodb): calendar controller --- .../src/controllers/calendars.controller.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 packages/nocodb/src/controllers/calendars.controller.ts diff --git a/packages/nocodb/src/controllers/calendars.controller.ts b/packages/nocodb/src/controllers/calendars.controller.ts new file mode 100644 index 0000000000..3d0c14120e --- /dev/null +++ b/packages/nocodb/src/controllers/calendars.controller.ts @@ -0,0 +1,71 @@ +import { + Body, + Controller, + Get, + HttpCode, + Param, + Patch, + Post, + Req, + UseGuards, +} from '@nestjs/common'; +import { Request } from 'express'; +import { ViewCreateReqType } from 'nocodb-sdk'; +import { GlobalGuard } from '~/guards/global/global.guard'; +import { CalendarsService } from '~/services/calendars.service'; +import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware'; +import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard'; + +@Controller() +@UseGuards(MetaApiLimiterGuard, GlobalGuard) +export class CalendarsController { + constructor(private readonly calendarsService: CalendarsService) {} + + @Get([ + '/api/v1/db/meta/calendars/:calendarViewId', + '/api/v2/meta/calendars/:calendarViewId', + ]) + @Acl('calendarViewGet') + async calendarViewGet(@Param('calendarViewId') calendarViewId: string) { + return await this.calendarsService.calendarViewGet({ + calendarViewId, + }); + } + + @Post([ + '/api/v1/db/meta/tables/:tableId/calendars', + '/api/v2/meta/tables/:tableId/calendars', + ]) + @HttpCode(200) + @Acl('calendarViewCreate') + async calendarViewCreate( + @Param('tableId') tableId: string, + @Body() body: ViewCreateReqType, + @Req() req: Request, + ) { + return await this.calendarsService.calendarViewCreate({ + tableId, + calendar: body, + user: req.user, + req, + }); + } + + @Patch([ + '/api/v1/db/meta/calendars/:calendarViewId', + '/api/v2/meta/calendars/:calendarViewId', + ]) + @Acl('calendarViewUpdate') + async calendarViewUpdate( + @Param('calendarViewId') calendarViewId: string, + @Body() body, + + @Req() req: Request, + ) { + return await this.calendarsService.calendarViewUpdate({ + calendarViewId, + calendar: body, + req, + }); + } +}