2022-10-10 15:42:15 +00:00
|
|
|
import type { NextApiRequest } from "next";
|
|
|
|
|
|
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
|
|
|
|
|
|
import {
|
|
|
|
schemaAvailabilityEditBodyParams,
|
|
|
|
schemaAvailabilityReadPublic,
|
|
|
|
} from "@lib/validations/availability";
|
|
|
|
import { schemaQueryIdParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /availabilities/{id}:
|
|
|
|
* patch:
|
|
|
|
* operationId: editAvailabilityById
|
|
|
|
* summary: Edit an existing availability
|
2022-11-18 19:18:07 +00:00
|
|
|
* parameters:
|
|
|
|
* - in: query
|
|
|
|
* name: apiKey
|
|
|
|
* required: true
|
|
|
|
* description: Your API key
|
|
|
|
* schema:
|
|
|
|
* type: integer
|
|
|
|
* - in: path
|
|
|
|
* name: id
|
|
|
|
* required: true
|
|
|
|
* schema:
|
|
|
|
* type: integer
|
|
|
|
* description: ID of the availability to edit
|
2022-10-10 15:42:15 +00:00
|
|
|
* requestBody:
|
|
|
|
* description: Edit an existing availability related to one of your bookings
|
|
|
|
* required: true
|
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
|
|
|
* type: object
|
|
|
|
* properties:
|
|
|
|
* days:
|
|
|
|
* type: array
|
2022-11-18 19:18:07 +00:00
|
|
|
* description: Array of integers depicting weekdays
|
|
|
|
* items:
|
|
|
|
* type: integer
|
|
|
|
* enum: [0, 1, 2, 3, 4, 5]
|
|
|
|
* scheduleId:
|
|
|
|
* type: integer
|
|
|
|
* description: ID of schedule this availability is associated with
|
2022-10-10 15:42:15 +00:00
|
|
|
* startTime:
|
|
|
|
* type: string
|
2022-11-18 19:18:07 +00:00
|
|
|
* description: Start time of the availability
|
2022-10-10 15:42:15 +00:00
|
|
|
* endTime:
|
|
|
|
* type: string
|
2022-11-18 19:18:07 +00:00
|
|
|
* description: End time of the availability
|
|
|
|
* examples:
|
|
|
|
* availability:
|
|
|
|
* summary: An example of availability
|
|
|
|
* value:
|
|
|
|
* scheduleId: 123
|
|
|
|
* days: [1,2,3,5]
|
|
|
|
* startTime: 1970-01-01T17:00:00.000Z
|
|
|
|
* endTime: 1970-01-01T17:00:00.000Z
|
|
|
|
*
|
2022-10-10 15:42:15 +00:00
|
|
|
* tags:
|
|
|
|
* - availabilities
|
|
|
|
* externalDocs:
|
|
|
|
* url: https://docs.cal.com/availability
|
|
|
|
* responses:
|
|
|
|
* 201:
|
|
|
|
* description: OK, availability edited successfully
|
|
|
|
* 400:
|
|
|
|
* description: Bad request. Availability body is invalid.
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
*/
|
|
|
|
export async function patchHandler(req: NextApiRequest) {
|
|
|
|
const { prisma, query, body } = req;
|
|
|
|
const { id } = schemaQueryIdParseInt.parse(query);
|
|
|
|
const data = schemaAvailabilityEditBodyParams.parse(body);
|
|
|
|
const availability = await prisma.availability.update({
|
|
|
|
where: { id },
|
|
|
|
data,
|
|
|
|
include: { Schedule: { select: { userId: true } } },
|
|
|
|
});
|
|
|
|
return { availability: schemaAvailabilityReadPublic.parse(availability) };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defaultResponder(patchHandler);
|