Files
cal.diy/apps/api/v2/src/modules/slots/controllers/slots.controller.ts
T
Morgan 9a473d5b55 chore: auth on api-v2 with api-key (#15455)
* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* chore: enable apiv2 auth with api keys

* fixup! chore: enable apiv2 auth with api keys

* fixup! Merge branch 'chore-apiv2-auth-api-key' of github.com:calcom/cal.com into chore-apiv2-auth-api-key

* fixup! fixup! Merge branch 'chore-apiv2-auth-api-key' of github.com:calcom/cal.com into chore-apiv2-auth-api-key

* fixup! fixup! fixup! Merge branch 'chore-apiv2-auth-api-key' of github.com:calcom/cal.com into chore-apiv2-auth-api-key
2024-06-19 16:00:22 +00:00

73 lines
2.1 KiB
TypeScript

import { API_VERSIONS_VALUES } from "@/lib/api-versions";
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
import { SlotsService } from "@/modules/slots/services/slots.service";
import { Query, Body, Controller, Get, Delete, Post, Req, Res, UseGuards } from "@nestjs/common";
import { ApiTags as DocsTags } from "@nestjs/swagger";
import { Response as ExpressResponse, Request as ExpressRequest } from "express";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
import { getAvailableSlots } from "@calcom/platform-libraries-0.0.2";
import type { AvailableSlotsType } from "@calcom/platform-libraries-0.0.2";
import { RemoveSelectedSlotInput, ReserveSlotInput } from "@calcom/platform-types";
import { ApiResponse, GetAvailableSlotsInput } from "@calcom/platform-types";
@Controller({
path: "/v2/slots",
version: API_VERSIONS_VALUES,
})
@DocsTags("Slots")
export class SlotsController {
constructor(private readonly slotsService: SlotsService) {}
@Post("/reserve")
async reserveSlot(
@Body() body: ReserveSlotInput,
@Res({ passthrough: true }) res: ExpressResponse,
@Req() req: ExpressRequest
): Promise<ApiResponse<string>> {
const uid = await this.slotsService.reserveSlot(body, req.cookies?.uid);
res.cookie("uid", uid);
return {
status: SUCCESS_STATUS,
data: uid,
};
}
@Delete("/selected-slot")
async deleteSelectedSlot(
@Query() params: RemoveSelectedSlotInput,
@Req() req: ExpressRequest
): Promise<ApiResponse> {
const uid = req.cookies?.uid || params.uid;
await this.slotsService.deleteSelectedslot(uid);
return {
status: SUCCESS_STATUS,
};
}
@Get("/available")
async getAvailableSlots(
@Query() query: GetAvailableSlotsInput,
@Req() req: ExpressRequest
): Promise<ApiResponse<AvailableSlotsType>> {
const isTeamEvent = await this.slotsService.checkIfIsTeamEvent(query.eventTypeId);
const availableSlots = await getAvailableSlots({
input: {
...query,
isTeamEvent,
},
ctx: {
req,
},
});
return {
data: availableSlots,
status: SUCCESS_STATUS,
};
}
}