fix: post / patch attendees docs w examples

This commit is contained in:
Agusti Fernandez Pardo committed 2022-04-27 19:25:36 +02:00
1 parent 14e2964a6d
commit e52af0bbef
55 files changed
+246 -233

No files matched your search

+25 -8
View File
@@ -14,7 +14,7 @@ import {
* @swagger
* /attendees/{id}:
* get:
* summary: Get an attendee by ID
* summary: Find an attendee by ID
* parameters:
* - in: path
* name: id
@@ -22,6 +22,7 @@ import {
* type: integer
* required: true
* description: Numeric ID of the attendee to get
* example: 3
* security:
* - ApiKeyAuth: []
* tags:
@@ -37,18 +38,34 @@ import {
* summary: Edit an existing attendee
* consumes:
* - application/json
* requestBody:
* description: Edit an existing attendee related to one of your bookings
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - bookingId
* - name
* - email
* - timeZone
* properties:
* email:
* type: string
* example: [email protected]
* name:
* type: string
* example: John Doe
* timeZone:
* type: string
* example: Europe/London
* parameters:
* - in: body
* name: attendee
* description: The attendee to edit
* schema:
* type: object
* $ref: '#/components/schemas/Attendee'
* required: true
* - in: path
* name: id
* schema:
* type: integer
* example: 3
* required: true
* description: Numeric ID of the attendee to edit
* security:
+38 -11
View File
@@ -10,7 +10,7 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v
* @swagger
* /attendees:
* get:
* summary: Get all attendees
* summary: Find all attendees
* security:
* - ApiKeyAuth: []
* tags:
@@ -26,6 +26,33 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v
* summary: Creates a new attendee
* security:
* - ApiKeyAuth: []
* consumes:
* - application/json
* requestBody:
* description: Create a new attendee related to one of your bookings
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - bookingId
* - name
* - email
* - timeZone
* properties:
* bookingId:
* type: number
* example: 1
* email:
* type: string
* example: [email protected]
* name:
* type: string
* example: John Doe
* timeZone:
* type: string
* example: Europe/London
* tags:
* - attendees
* responses:
@@ -61,11 +88,12 @@ async function createOrlistAllAttendees(
error,
});
} else if (method === "POST") {
const safe = schemaAttendeeCreateBodyParams.safeParse(req.body);
if (!safe.success) {
throw new Error("Invalid request body", safe.error);
const safePost = schemaAttendeeCreateBodyParams.safeParse(req.body);
if (!safePost.success) {
console.log(safePost.error);
res.status(400).json({ error: safePost.error });
throw new Error("Invalid request body", safePost.error);
}
const bookingId = safe.data.bookingId;
const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
@@ -76,15 +104,14 @@ async function createOrlistAllAttendees(
}
const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat();
// Here we make sure to only return attendee's of the user's own bookings.
if (!userBookingIds.includes(parseInt(safe.data.bookingId)))
res.status(401).json({ message: "Unauthorized" });
if (!userBookingIds.includes(safePost.data.bookingId)) res.status(401).json({ message: "Unauthorized" });
else {
delete safe.data.bookingId;
const noBookingId = safe.data;
const data = await prisma.attendee.create({
data: {
...noBookingId,
booking: { connect: { id: parseInt(bookingId) } },
email: safePost.data.email,
name: safePost.data.name,
timeZone: safePost.data.timeZone,
booking: { connect: { id: safePost.data.bookingId } },
},
});
const attendee = schemaAttendeeReadPublic.parse(data);
+1 -1
View File
@@ -17,7 +17,7 @@ import {
* @swagger
* /availabilities/{id}:
* get:
* summary: Get an availability by ID
* summary: Find an availability by ID
* parameters:
* - in: path
* name: id
+1 -1
View File
@@ -13,7 +13,7 @@ import {
* @swagger
* /availabilities:
* get:
* summary: Get all availabilities
* summary: Find all availabilities
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -18,7 +18,7 @@ import {
* @swagger
* /booking-references/{id}:
* get:
* summary: Get a booking reference by ID
* summary: Find a booking reference by ID
* parameters:
* - in: path
* name: id
+1 -1
View File
@@ -13,7 +13,7 @@ import {
* @swagger
* /booking-references:
* get:
* summary: Get all booking references
* summary: Find all booking references
* security:
* - ApiKeyAuth: []
* tags:
+6 -5
View File
@@ -4,7 +4,7 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BookingResponse } from "@lib/types";
import { schemaBookingBodyParams, schemaBookingPublic } from "@lib/validations/booking";
import { schemaBookingEditBodyParams, schemaBookingReadPublic } from "@lib/validations/booking";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
@@ -14,7 +14,7 @@ import {
* @swagger
* /bookings/{id}:
* get:
* summary: Get a booking by ID
* summary: Find a booking by ID
* parameters:
* - in: path
* name: id
@@ -88,7 +88,6 @@ import {
export async function bookingById(req: NextApiRequest, res: NextApiResponse<BookingResponse>) {
const { method, query, body } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaBookingBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
@@ -103,7 +102,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
case "GET":
await prisma.booking
.findUnique({ where: { id: safeQuery.data.id } })
.then((data) => schemaBookingPublic.parse(data))
.then((data) => schemaBookingReadPublic.parse(data))
.then((booking) => res.status(200).json({ booking }))
.catch((error: Error) =>
res.status(404).json({
@@ -114,6 +113,8 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
break;
case "PATCH":
const safeBody = schemaBookingEditBodyParams.safeParse(body);
if (!safeBody.success) {
throw new Error("Invalid request body");
}
@@ -122,7 +123,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
where: { id: safeQuery.data.id },
data: safeBody.data,
})
.then((data) => schemaBookingPublic.parse(data))
.then((data) => schemaBookingReadPublic.parse(data))
.then((booking) => res.status(200).json({ booking }))
.catch((error: Error) =>
res.status(404).json({
+5 -5
View File
@@ -4,13 +4,13 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { BookingResponse, BookingsResponse } from "@lib/types";
import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "@lib/validations/booking";
import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking";
/**
* @swagger
* /bookings:
* get:
* summary: Get all bookings
* summary: Find all bookings
* security:
* - ApiKeyAuth: []
* tags:
@@ -46,7 +46,7 @@ async function createOrlistAllBookings(
if (method === "GET") {
const data = await prisma.booking.findMany({ where: { userId } });
const bookings = data.map((booking) => schemaBookingPublic.parse(booking));
const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking));
if (bookings) res.status(200).json({ bookings });
else
(error: Error) =>
@@ -55,11 +55,11 @@ async function createOrlistAllBookings(
error,
});
} else if (method === "POST") {
const safe = schemaBookingBodyParams.safeParse(req.body);
const safe = schemaBookingCreateBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.booking.create({ data: { ...safe.data, userId } });
const booking = schemaBookingPublic.parse(data);
const booking = schemaBookingReadPublic.parse(data);
if (booking) res.status(201).json({ booking, message: "Booking created successfully" });
else
+6 -6
View File
@@ -5,8 +5,8 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DailyEventReferenceResponse } from "@lib/types";
import {
schemaDailyEventReferenceBodyParams,
schemaDailyEventReferencePublic,
schemaDailyEventReferenceEditBodyParams,
schemaDailyEventReferenceReadPublic,
} from "@lib/validations/daily-event-reference";
import {
schemaQueryIdParseInt,
@@ -17,7 +17,7 @@ import {
* @swagger
* /daily-event-references/{id}:
* get:
* summary: Get a daily event reference by ID
* summary: Find a daily event reference by ID
* parameters:
* - in: path
* name: id
@@ -94,7 +94,7 @@ export async function dailyEventReferenceById(
) {
const { method, query, body } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDailyEventReferenceBodyParams.safeParse(body);
const safeBody = schemaDailyEventReferenceEditBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
const userId = req.userId;
const userBookings = await prisma.booking.findMany({ where: { userId } });
@@ -112,7 +112,7 @@ export async function dailyEventReferenceById(
case "GET":
await prisma.dailyEventReference
.findUnique({ where: { id: safeQuery.data.id } })
.then((data) => schemaDailyEventReferencePublic.parse(data))
.then((data) => schemaDailyEventReferenceReadPublic.parse(data))
.then((daily_event_reference) => res.status(200).json({ daily_event_reference }))
.catch((error: Error) =>
res.status(404).json({
@@ -128,7 +128,7 @@ export async function dailyEventReferenceById(
}
await prisma.dailyEventReference
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
.then((data) => schemaDailyEventReferencePublic.parse(data))
.then((data) => schemaDailyEventReferenceReadPublic.parse(data))
.then((daily_event_reference) => res.status(200).json({ daily_event_reference }))
.catch((error: Error) =>
res.status(404).json({
+6 -6
View File
@@ -5,15 +5,15 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DailyEventReferenceResponse, DailyEventReferencesResponse } from "@lib/types";
import {
schemaDailyEventReferenceBodyParams,
schemaDailyEventReferencePublic,
schemaDailyEventReferenceCreateBodyParams,
schemaDailyEventReferenceReadPublic,
} from "@lib/validations/daily-event-reference";
/**
* @swagger
* /daily-event-references:
* get:
* summary: Get all daily event reference
* summary: Find all daily event reference
* security:
* - ApiKeyAuth: []
* tags:
@@ -54,7 +54,7 @@ async function createOrlistAllDailyEventReferences(
where: { bookingId: { in: userBookingIds } },
});
const daily_event_references = data.map((dailyEventReference) =>
schemaDailyEventReferencePublic.parse(dailyEventReference)
schemaDailyEventReferenceReadPublic.parse(dailyEventReference)
);
if (daily_event_references) res.status(200).json({ daily_event_references });
else
@@ -64,11 +64,11 @@ async function createOrlistAllDailyEventReferences(
error,
});
} else if (method === "POST") {
const safe = schemaDailyEventReferenceBodyParams.safeParse(req.body);
const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.dailyEventReference.create({ data: safe.data });
const daily_event_reference = schemaDailyEventReferencePublic.parse(data);
const daily_event_reference = schemaDailyEventReferenceReadPublic.parse(data);
if (daily_event_reference)
res.status(201).json({ daily_event_reference, message: "DailyEventReference created successfully" });
+6 -6
View File
@@ -5,8 +5,8 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DestinationCalendarResponse } from "@lib/types";
import {
schemaDestinationCalendarBodyParams,
schemaDestinationCalendarPublic,
schemaDestinationCalendarEditBodyParams,
schemaDestinationCalendarReadPublic,
} from "@lib/validations/destination-calendar";
import {
schemaQueryIdParseInt,
@@ -17,7 +17,7 @@ import {
* @swagger
* /destination-calendars/{id}:
* get:
* summary: Get a destination calendar by ID
* summary: Find a destination calendar by ID
* parameters:
* - in: path
* name: id
@@ -94,7 +94,7 @@ export async function destionationCalendarById(
) {
const { method, query, body } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDestinationCalendarBodyParams.safeParse(body);
const safeBody = schemaDestinationCalendarEditBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
const userId = req.userId;
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
@@ -107,7 +107,7 @@ export async function destionationCalendarById(
case "GET":
await prisma.destinationCalendar
.findUnique({ where: { id: safeQuery.data.id } })
.then((data) => schemaDestinationCalendarPublic.parse(data))
.then((data) => schemaDestinationCalendarReadPublic.parse(data))
.then((destination_calendar) => res.status(200).json({ destination_calendar }))
.catch((error: Error) =>
res.status(404).json({
@@ -123,7 +123,7 @@ export async function destionationCalendarById(
}
await prisma.destinationCalendar
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
.then((data) => schemaDestinationCalendarPublic.parse(data))
.then((data) => schemaDestinationCalendarReadPublic.parse(data))
.then((destination_calendar) => res.status(200).json({ destination_calendar }))
.catch((error: Error) =>
res.status(404).json({
+6 -6
View File
@@ -5,15 +5,15 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DestinationCalendarResponse, DestinationCalendarsResponse } from "@lib/types";
import {
schemaDestinationCalendarBodyParams,
schemaDestinationCalendarPublic,
schemaDestinationCalendarCreateBodyParams,
schemaDestinationCalendarReadPublic,
} from "@lib/validations/destination-calendar";
/**
* @swagger
* /destination-calendars:
* get:
* summary: Get all destination calendars
* summary: Find all destination calendars
* security:
* - ApiKeyAuth: []
* tags:
@@ -50,7 +50,7 @@ async function createOrlistAllDestinationCalendars(
if (method === "GET") {
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
const destination_calendars = data.map((destinationCalendar) =>
schemaDestinationCalendarPublic.parse(destinationCalendar)
schemaDestinationCalendarReadPublic.parse(destinationCalendar)
);
if (data) res.status(200).json({ destination_calendars });
else
@@ -60,11 +60,11 @@ async function createOrlistAllDestinationCalendars(
error,
});
} else if (method === "POST") {
const safe = schemaDestinationCalendarBodyParams.safeParse(req.body);
const safe = schemaDestinationCalendarCreateBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body");
const data = await prisma.destinationCalendar.create({ data: { ...safe.data, userId } });
const destination_calendar = schemaDestinationCalendarPublic.parse(data);
const destination_calendar = schemaDestinationCalendarReadPublic.parse(data);
if (destination_calendar)
res.status(201).json({ destination_calendar, message: "DestinationCalendar created successfully" });
+1
View File
@@ -20,6 +20,7 @@ const swaggerHandler = withSwagger({
},
components: {
securitySchemes: { ApiKeyAuth: { type: "apiKey", in: "query", name: "apiKey" } },
security: { ApiKeyAuth: [] },
schemas: { ...jsonSchema.definitions },
},
},
+1 -1
View File
@@ -17,7 +17,7 @@ import {
* @swagger
* /event-type-custom-inputs/{id}:
* get:
* summary: Get a eventTypeCustomInput by ID
* summary: Find a eventTypeCustomInput by ID
* parameters:
* - in: path
* name: id
+1 -1
View File
@@ -13,7 +13,7 @@ import {
* @swagger
* /event-type-custom-inputs:
* get:
* summary: Get all eventTypeCustomInputs
* summary: Find all eventTypeCustomInputs
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -14,7 +14,7 @@ import {
* @swagger
* /event-types/{id}:
* get:
* summary: Get a eventType by ID
* summary: Find a eventType by ID
* parameters:
* - in: path
* name: id
+1 -1
View File
@@ -10,7 +10,7 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validatio
* @swagger
* /event-types:
* get:
* summary: Get all event types
* summary: Find all event types
* security:
* - ApiKeyAuth: []
* tags:
+5
View File
@@ -1,5 +1,10 @@
import type { NextApiRequest, NextApiResponse } from "next";
/**
* @swagger
* security:
* - ApiKeyAuth: []
*/
export default async function CalcomApi(_: NextApiRequest, res: NextApiResponse) {
res.status(201).json({ message: "Welcome to Cal.com API - docs are at https://docs.cal.com/api" });
}
+1 -1
View File
@@ -11,7 +11,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
* @swagger
* /memberships/{userId}_{teamId}:
* get:
* summary: Get a membership by userID and teamID
* summary: Find a membership by userID and teamID
* parameters:
* - in: path
* name: userId
+1 -1
View File
@@ -10,7 +10,7 @@ import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validat
* @swagger
* /memberships:
* get:
* summary: Get all memberships
* summary: Find all memberships
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -14,7 +14,7 @@ import {
* @swagger
* /payments/{id}:
* get:
* summary: Get one of your own payments by ID
* summary: Find one of your own payments by ID
* parameters:
* - in: path
* name: id
+1 -1
View File
@@ -10,7 +10,7 @@ import { schemaPaymentPublic } from "@lib/validations/payment";
* @swagger
* /payments:
* get:
* summary: Get all payments
* summary: Find all payments
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -14,7 +14,7 @@ import {
* @swagger
* /schedules/{id}:
* get:
* summary: Get a schedule by ID
* summary: Find a schedule by ID
* parameters:
* - in: path
* name: id
+2 -2
View File
@@ -4,13 +4,13 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { ScheduleResponse, SchedulesResponse } from "@lib/types";
import { schemaScheduleBodyParams, schemaSchedulePublic, withValidSchedule } from "@lib/validations/schedule";
import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule";
/**
* @swagger
* /schedules:
* get:
* summary: Get all schedules
* summary: Find all schedules
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -14,7 +14,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
* @swagger
* /selected-calendars/{userId}_{integration}_{externalId}:
* get:
* summary: Get a selected-calendar by userID and teamID
* summary: Find a selected-calendar by userID and teamID
* parameters:
* - in: path
* name: userId
+1 -1
View File
@@ -13,7 +13,7 @@ import {
* @swagger
* /selected-calendars:
* get:
* summary: Get all selected calendars
* summary: Find all selected calendars
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -14,7 +14,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
* @swagger
* /teams/{id}:
* get:
* summary: Get a team by ID
* summary: Find a team by ID
* parameters:
* - in: path
* name: id
+2 -2
View File
@@ -5,13 +5,13 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { TeamResponse, TeamsResponse } from "@lib/types";
import { schemaMembershipPublic } from "@lib/validations/membership";
import { schemaTeamBodyParams, schemaTeamPublic, withValidTeam } from "@lib/validations/team";
import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
/**
* @swagger
* /teams:
* get:
* summary: Get all teams
* summary: Find all teams
* security:
* - ApiKeyAuth: []
* tags:
+1 -1
View File
@@ -14,7 +14,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations
* @swagger
* /users/{id}:
* get:
* summary: Get a user by ID, returns your user if regular user.
* summary: Find a user by ID, returns your user if regular user.
* parameters:
* - in: path
* name: id
+1 -1
View File
@@ -10,7 +10,7 @@ import { schemaUserReadPublic } from "@lib/validations/user";
* @swagger
* /users:
* get:
* summary: Get all users (admin only), returns your user if regular user.
* summary: Find all users (admin only), returns your user if regular user.
* security:
* - ApiKeyAuth: []
* tags: