* refactor: event-types CREATE, UPDATE accept scheduleId and return scheduleId * chore: enable passing scheduleId to event-types create handler * chore: use platform-libraries at version 0.0.20 * fix: remove team output schedule * finish merge main into this branch * fix: dont allow adding scheduleId to event-type if user does not own schedule
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { API_VERSIONS_VALUES } from "@/lib/api-versions";
|
|
import { SlotsService } from "@/modules/slots/services/slots.service";
|
|
import { Query, Body, Controller, Get, Delete, Post, Req, Res } 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.20";
|
|
import type { AvailableSlotsType } from "@calcom/platform-libraries-0.0.20";
|
|
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,
|
|
};
|
|
}
|
|
}
|