From bb28680413c9b989604f0f26f8aef5d7bb51ad46 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 01:38:40 +0200 Subject: [PATCH 01/11] fixes all openapi spect issues, removes json-schema auto-generated moving to manual examples --- json-schema/json-schema.json | 136 ++++++++++---------- pages/api/attendees/[id].ts | 13 +- pages/api/attendees/index.ts | 9 +- pages/api/availabilities/[id].ts | 20 +-- pages/api/availabilities/index.ts | 7 +- pages/api/booking-references/[id].ts | 21 +-- pages/api/booking-references/index.ts | 8 +- pages/api/bookings/[id].ts | 21 +-- pages/api/bookings/index.ts | 7 +- pages/api/daily-event-references/[id].ts | 21 +-- pages/api/daily-event-references/index.ts | 7 +- pages/api/destination-calendars/[id].ts | 21 +-- pages/api/destination-calendars/index.ts | 7 +- pages/api/docs.ts | 19 +-- pages/api/event-type-custom-inputs/[id].ts | 27 +--- pages/api/event-type-custom-inputs/index.ts | 7 +- pages/api/event-types/[id].ts | 11 -- pages/api/event-types/index.ts | 7 +- pages/api/index.ts | 5 - pages/api/memberships/[id].ts | 21 +-- pages/api/memberships/index.ts | 7 +- pages/api/payments/[id].ts | 3 +- pages/api/payments/index.ts | 3 +- pages/api/schedules/[id].ts | 22 +--- pages/api/schedules/index.ts | 7 +- pages/api/selected-calendars/[id].ts | 20 +-- pages/api/selected-calendars/index.ts | 7 +- pages/api/teams/[id].ts | 22 +--- pages/api/teams/index.ts | 7 +- pages/api/users/[id].ts | 19 +-- pages/api/users/index.ts | 3 +- templates/endpoints/[id]/delete.ts | 4 +- templates/endpoints/[id]/edit.ts | 4 +- templates/endpoints/[id]/index.ts | 3 +- templates/endpoints/get_all.ts | 3 +- templates/endpoints/get_all_and_post.ts | 7 +- templates/endpoints/post.ts | 4 +- 37 files changed, 154 insertions(+), 386 deletions(-) diff --git a/json-schema/json-schema.json b/json-schema/json-schema.json index 1ae113fddf..f6a197e4a5 100644 --- a/json-schema/json-schema.json +++ b/json-schema/json-schema.json @@ -36,7 +36,7 @@ "users": { "type": "array", "items": { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" } }, "userId": { @@ -45,7 +45,7 @@ "team": { "anyOf": [ { - "$ref": "#/definitions/Team" + "$ref": "#/components/schemas/Team" }, { "type": "null" @@ -55,25 +55,25 @@ "bookings": { "type": "array", "items": { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" } }, "availability": { "type": "array", "items": { - "$ref": "#/definitions/Availability" + "$ref": "#/components/schemas/Availability" } }, "webhooks": { "type": "array", "items": { - "$ref": "#/definitions/Webhook" + "$ref": "#/components/schemas/Webhook" } }, "destinationCalendar": { "anyOf": [ { - "$ref": "#/definitions/DestinationCalendar" + "$ref": "#/components/schemas/DestinationCalendar" }, { "type": "null" @@ -86,7 +86,7 @@ "customInputs": { "type": "array", "items": { - "$ref": "#/definitions/EventTypeCustomInput" + "$ref": "#/components/schemas/EventTypeCustomInput" } }, "timeZone": { @@ -138,7 +138,7 @@ "schedule": { "anyOf": [ { - "$ref": "#/definitions/Schedule" + "$ref": "#/components/schemas/Schedule" }, { "type": "null" @@ -176,7 +176,7 @@ "user": { "anyOf": [ { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, { "type": "null" @@ -200,7 +200,7 @@ "user": { "anyOf": [ { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, { "type": "null" @@ -210,7 +210,7 @@ "booking": { "anyOf": [ { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" }, { "type": "null" @@ -220,7 +220,7 @@ "eventType": { "anyOf": [ { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, { "type": "null" @@ -296,31 +296,31 @@ "eventTypes": { "type": "array", "items": { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" } }, "credentials": { "type": "array", "items": { - "$ref": "#/definitions/Credential" + "$ref": "#/components/schemas/Credential" } }, "teams": { "type": "array", "items": { - "$ref": "#/definitions/Membership" + "$ref": "#/components/schemas/Membership" } }, "bookings": { "type": "array", "items": { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" } }, "schedules": { "type": "array", "items": { - "$ref": "#/definitions/Schedule" + "$ref": "#/components/schemas/Schedule" } }, "defaultScheduleId": { @@ -329,7 +329,7 @@ "selectedCalendars": { "type": "array", "items": { - "$ref": "#/definitions/SelectedCalendar" + "$ref": "#/components/schemas/SelectedCalendar" } }, "completedOnboarding": { @@ -361,7 +361,7 @@ "availability": { "type": "array", "items": { - "$ref": "#/definitions/Availability" + "$ref": "#/components/schemas/Availability" } }, "invitedTo": { @@ -375,7 +375,7 @@ "webhooks": { "type": "array", "items": { - "$ref": "#/definitions/Webhook" + "$ref": "#/components/schemas/Webhook" } }, "brandColor": { @@ -389,7 +389,7 @@ "destinationCalendar": { "anyOf": [ { - "$ref": "#/definitions/DestinationCalendar" + "$ref": "#/components/schemas/DestinationCalendar" }, { "type": "null" @@ -410,7 +410,7 @@ "apiKeys": { "type": "array", "items": { - "$ref": "#/definitions/ApiKey" + "$ref": "#/components/schemas/ApiKey" } } } @@ -440,13 +440,13 @@ "members": { "type": "array", "items": { - "$ref": "#/definitions/Membership" + "$ref": "#/components/schemas/Membership" } }, "eventTypes": { "type": "array", "items": { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" } } } @@ -463,10 +463,10 @@ "enum": ["MEMBER", "ADMIN", "OWNER"] }, "team": { - "$ref": "#/definitions/Team" + "$ref": "#/components/schemas/Team" }, "user": { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" } } }, @@ -520,7 +520,7 @@ "booking": { "anyOf": [ { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" }, { "type": "null" @@ -551,7 +551,7 @@ "booking": { "anyOf": [ { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" }, { "type": "null" @@ -577,7 +577,7 @@ "booking": { "anyOf": [ { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" }, { "type": "null" @@ -598,7 +598,7 @@ "user": { "anyOf": [ { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, { "type": "null" @@ -608,13 +608,13 @@ "references": { "type": "array", "items": { - "$ref": "#/definitions/BookingReference" + "$ref": "#/components/schemas/BookingReference" } }, "eventType": { "anyOf": [ { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, { "type": "null" @@ -638,7 +638,7 @@ "attendees": { "type": "array", "items": { - "$ref": "#/definitions/Attendee" + "$ref": "#/components/schemas/Attendee" } }, "location": { @@ -647,7 +647,7 @@ "dailyRef": { "anyOf": [ { - "$ref": "#/definitions/DailyEventReference" + "$ref": "#/components/schemas/DailyEventReference" }, { "type": "null" @@ -682,13 +682,13 @@ "payment": { "type": "array", "items": { - "$ref": "#/definitions/Payment" + "$ref": "#/components/schemas/Payment" } }, "destinationCalendar": { "anyOf": [ { - "$ref": "#/definitions/DestinationCalendar" + "$ref": "#/components/schemas/DestinationCalendar" }, { "type": "null" @@ -710,12 +710,12 @@ "type": "integer" }, "user": { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, "eventType": { "anyOf": [ { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, { "type": "null" @@ -731,7 +731,7 @@ "availability": { "type": "array", "items": { - "$ref": "#/definitions/Availability" + "$ref": "#/components/schemas/Availability" } } } @@ -745,7 +745,7 @@ "user": { "anyOf": [ { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, { "type": "null" @@ -755,7 +755,7 @@ "eventType": { "anyOf": [ { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, { "type": "null" @@ -783,7 +783,7 @@ "Schedule": { "anyOf": [ { - "$ref": "#/definitions/Schedule" + "$ref": "#/components/schemas/Schedule" }, { "type": "null" @@ -796,7 +796,7 @@ "type": "object", "properties": { "user": { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, "integration": { "type": "string" @@ -813,7 +813,7 @@ "type": "integer" }, "eventType": { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, "label": { "type": "string" @@ -892,7 +892,7 @@ "booking": { "anyOf": [ { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" }, { "type": "null" @@ -949,7 +949,7 @@ "user": { "anyOf": [ { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, { "type": "null" @@ -959,7 +959,7 @@ "eventType": { "anyOf": [ { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, { "type": "null" @@ -977,7 +977,7 @@ "user": { "anyOf": [ { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, { "type": "null" @@ -1001,64 +1001,64 @@ "type": "object", "properties": { "eventType": { - "$ref": "#/definitions/EventType" + "$ref": "#/components/schemas/EventType" }, "credential": { - "$ref": "#/definitions/Credential" + "$ref": "#/components/schemas/Credential" }, "destinationCalendar": { - "$ref": "#/definitions/DestinationCalendar" + "$ref": "#/components/schemas/DestinationCalendar" }, "user": { - "$ref": "#/definitions/User" + "$ref": "#/components/schemas/User" }, "team": { - "$ref": "#/definitions/Team" + "$ref": "#/components/schemas/Team" }, "membership": { - "$ref": "#/definitions/Membership" + "$ref": "#/components/schemas/Membership" }, "verificationRequest": { - "$ref": "#/definitions/VerificationRequest" + "$ref": "#/components/schemas/VerificationRequest" }, "bookingReference": { - "$ref": "#/definitions/BookingReference" + "$ref": "#/components/schemas/BookingReference" }, "attendee": { - "$ref": "#/definitions/Attendee" + "$ref": "#/components/schemas/Attendee" }, "dailyEventReference": { - "$ref": "#/definitions/DailyEventReference" + "$ref": "#/components/schemas/DailyEventReference" }, "booking": { - "$ref": "#/definitions/Booking" + "$ref": "#/components/schemas/Booking" }, "schedule": { - "$ref": "#/definitions/Schedule" + "$ref": "#/components/schemas/Schedule" }, "availability": { - "$ref": "#/definitions/Availability" + "$ref": "#/components/schemas/Availability" }, "selectedCalendar": { - "$ref": "#/definitions/SelectedCalendar" + "$ref": "#/components/schemas/SelectedCalendar" }, "eventTypeCustomInput": { - "$ref": "#/definitions/EventTypeCustomInput" + "$ref": "#/components/schemas/EventTypeCustomInput" }, "resetPasswordRequest": { - "$ref": "#/definitions/ResetPasswordRequest" + "$ref": "#/components/schemas/ResetPasswordRequest" }, "reminderMail": { - "$ref": "#/definitions/ReminderMail" + "$ref": "#/components/schemas/ReminderMail" }, "payment": { - "$ref": "#/definitions/Payment" + "$ref": "#/components/schemas/Payment" }, "webhook": { - "$ref": "#/definitions/Webhook" + "$ref": "#/components/schemas/Webhook" }, "apiKey": { - "$ref": "#/definitions/ApiKey" + "$ref": "#/components/schemas/ApiKey" } } } diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index ce41228cd0..b27c2e40fb 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -23,8 +23,7 @@ import { * required: true * description: Numeric ID of the attendee to get * example: 3 - * security: - * - ApiKeyAuth: [] + * tags: * - attendees * responses: @@ -36,8 +35,6 @@ import { * description: Attendee was not found * patch: * summary: Edit an existing attendee - * consumes: - * - application/json * requestBody: * description: Edit an existing attendee related to one of your bookings * required: true @@ -68,14 +65,12 @@ import { * example: 3 * required: true * description: Numeric ID of the attendee to edit - * security: - * - ApiKeyAuth: [] + * tags: * - attendees * responses: * 201: * description: OK, attendee edited successfuly - * model: Attendee * 400: * description: Bad request. Attendee body is invalid. * 401: @@ -89,14 +84,12 @@ import { * type: integer * required: true * description: Numeric ID of the attendee to delete - * security: - * - ApiKeyAuth: [] + * tags: * - attendees * responses: * 201: * description: OK, attendee removed successfuly - * model: Attendee * 400: * description: Bad request. Attendee id is invalid. * 401: diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.ts index 3adbc8a78c..a0514bb8df 100644 --- a/pages/api/attendees/index.ts +++ b/pages/api/attendees/index.ts @@ -11,8 +11,7 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v * /attendees: * get: * summary: Find all attendees - * security: - * - ApiKeyAuth: [] + * tags: * - attendees * responses: @@ -24,10 +23,7 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v * description: No attendees were found * post: * summary: Creates a new attendee - * security: - * - ApiKeyAuth: [] - * consumes: - * - application/json + * requestBody: * description: Create a new attendee related to one of your bookings * required: true @@ -58,7 +54,6 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v * responses: * 201: * description: OK, attendee created - * model: Attendee * 400: * description: Bad request. Attendee body is invalid. * 401: diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts index 65f750dba7..ad6826a6d3 100644 --- a/pages/api/availabilities/[id].ts +++ b/pages/api/availabilities/[id].ts @@ -25,8 +25,7 @@ import { * type: integer * required: true * description: Numeric ID of the availability to get - * security: - * - ApiKeyAuth: [] + * tags: * - availabilities * externalDocs: @@ -40,24 +39,14 @@ import { * description: Availability was not found * patch: * summary: Edit an existing availability - * consumes: - * - application/json * parameters: - * - in: body - * name: availability - * description: The availability to edit - * schema: - * type: object - * $ref: '#/components/schemas/Availability' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the availability to edit - * security: - * - ApiKeyAuth: [] + * tags: * - availabilities * externalDocs: @@ -65,7 +54,6 @@ import { * responses: * 201: * description: OK, availability edited successfuly - * model: Availability * 400: * description: Bad request. Availability body is invalid. * 401: @@ -79,8 +67,7 @@ import { * type: integer * required: true * description: Numeric ID of the availability to delete - * security: - * - ApiKeyAuth: [] + * tags: * - availabilities * externalDocs: @@ -88,7 +75,6 @@ import { * responses: * 201: * description: OK, availability removed successfuly - * model: Availability * 400: * description: Bad request. Availability id is invalid. * 401: diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts index 3e519bc6ad..7d8f18eac3 100644 --- a/pages/api/availabilities/index.ts +++ b/pages/api/availabilities/index.ts @@ -14,8 +14,7 @@ import { * /availabilities: * get: * summary: Find all availabilities - * security: - * - ApiKeyAuth: [] + * tags: * - availabilities * externalDocs: @@ -29,8 +28,7 @@ import { * description: No availabilities were found * post: * summary: Creates a new availability - * security: - * - ApiKeyAuth: [] + * tags: * - availabilities * externalDocs: @@ -38,7 +36,6 @@ import { * responses: * 201: * description: OK, availability created - * model: Availability * 400: * description: Bad request. Availability body is invalid. * 401: diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index 21b314f728..4014707eb4 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -26,8 +26,7 @@ import { * type: integer * required: true * description: Numeric ID of the booking reference to get - * security: - * - ApiKeyAuth: [] + * tags: * - booking-references * responses: @@ -39,30 +38,20 @@ import { * description: BookingReference was not found * patch: * summary: Edit an existing booking reference - * consumes: - * - application/json + * parameters: - * - in: body - * name: bookingReference - * description: The bookingReference to edit - * schema: - * type: object - * $ref: '#/components/schemas/BookingReference' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the booking reference to edit - * security: - * - ApiKeyAuth: [] + * tags: * - booking-references * responses: * 201: * description: OK, bookingReference edited successfuly - * model: BookingReference * 400: * description: Bad request. BookingReference body is invalid. * 401: @@ -76,14 +65,12 @@ import { * type: integer * required: true * description: Numeric ID of the booking reference to delete - * security: - * - ApiKeyAuth: [] + * tags: * - booking-references * responses: * 201: * description: OK, bookingReference removed successfuly - * model: BookingReference * 400: * description: Bad request. BookingReference id is invalid. * 401: diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts index bc82f23701..c214b305db 100644 --- a/pages/api/booking-references/index.ts +++ b/pages/api/booking-references/index.ts @@ -14,8 +14,7 @@ import { * /booking-references: * get: * summary: Find all booking references - * security: - * - ApiKeyAuth: [] + * tags: * - booking-references * responses: @@ -27,14 +26,13 @@ import { * description: No booking references were found * post: * summary: Creates a new booking reference - * security: - * - ApiKeyAuth: [] + * tags: * - booking-references * responses: * 201: * description: OK, booking reference created - * model: BookingReference + * 400: * description: Bad request. BookingReference body is invalid. * 401: diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts index 21be432cd1..9c1b647b20 100644 --- a/pages/api/bookings/[id].ts +++ b/pages/api/bookings/[id].ts @@ -22,8 +22,7 @@ import { * type: integer * required: true * description: Numeric ID of the booking to get - * security: - * - ApiKeyAuth: [] + * tags: * - bookings * responses: @@ -35,30 +34,20 @@ import { * description: Booking was not found * patch: * summary: Edit an existing booking - * consumes: - * - application/json + * parameters: - * - in: body - * name: booking - * description: The booking to edit - * schema: - * type: object - * $ref: '#/components/schemas/Booking' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the booking to edit - * security: - * - ApiKeyAuth: [] + * tags: * - bookings * responses: * 201: * description: OK, booking edited successfuly - * model: Booking * 400: * description: Bad request. Booking body is invalid. * 401: @@ -72,14 +61,12 @@ import { * type: integer * required: true * description: Numeric ID of the booking to delete - * security: - * - ApiKeyAuth: [] + * tags: * - bookings * responses: * 201: * description: OK, booking removed successfuly - * model: Booking * 400: * description: Bad request. Booking id is invalid. * 401: diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 8bb9cae30d..311a79b4dd 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -11,8 +11,7 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val * /bookings: * get: * summary: Find all bookings - * security: - * - ApiKeyAuth: [] + * tags: * - bookings * responses: @@ -24,14 +23,12 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val * description: No bookings were found * post: * summary: Creates a new booking - * security: - * - ApiKeyAuth: [] + * tags: * - bookings * responses: * 201: * description: OK, booking created - * model: Booking * 400: * description: Bad request. Booking body is invalid. * 401: diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/daily-event-references/[id].ts index 6ef4ac01e2..a59beeebbf 100644 --- a/pages/api/daily-event-references/[id].ts +++ b/pages/api/daily-event-references/[id].ts @@ -25,8 +25,7 @@ import { * type: integer * required: true * description: Numeric ID of the daily event reference to get - * security: - * - ApiKeyAuth: [] + * tags: * - daily-event-references * responses: @@ -38,30 +37,20 @@ import { * description: DailyEventReference was not found * patch: * summary: Edit an existing daily event reference - * consumes: - * - application/json + * parameters: - * - in: body - * name: dailyEventReference - * description: The dailyEventReference to edit - * schema: - * type: object - * $ref: '#/components/schemas/DailyEventReference' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the daily event reference to edit - * security: - * - ApiKeyAuth: [] + * tags: * - daily-event-references * responses: * 201: * description: OK, dailyEventReference edited successfuly - * model: DailyEventReference * 400: * description: Bad request. DailyEventReference body is invalid. * 401: @@ -75,14 +64,12 @@ import { * type: integer * required: true * description: Numeric ID of the daily event reference to delete - * security: - * - ApiKeyAuth: [] + * tags: * - daily-event-references * responses: * 201: * description: OK, dailyEventReference removed successfuly - * model: DailyEventReference * 400: * description: Bad request. DailyEventReference id is invalid. * 401: diff --git a/pages/api/daily-event-references/index.ts b/pages/api/daily-event-references/index.ts index dfafe246ce..290469f307 100644 --- a/pages/api/daily-event-references/index.ts +++ b/pages/api/daily-event-references/index.ts @@ -14,8 +14,7 @@ import { * /daily-event-references: * get: * summary: Find all daily event reference - * security: - * - ApiKeyAuth: [] + * tags: * - daily-event-references * responses: @@ -27,14 +26,12 @@ import { * description: No daily event references were found * post: * summary: Creates a new daily event reference - * security: - * - ApiKeyAuth: [] + * tags: * - daily-event-references * responses: * 201: * description: OK, daily event reference created - * model: DailyEventReference * 400: * description: Bad request. DailyEventReference body is invalid. * 401: diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts index 60982a7058..ecfe646b09 100644 --- a/pages/api/destination-calendars/[id].ts +++ b/pages/api/destination-calendars/[id].ts @@ -25,8 +25,7 @@ import { * type: integer * required: true * description: Numeric ID of the destination calendar to get - * security: - * - ApiKeyAuth: [] + * tags: * - destination-calendars * responses: @@ -38,30 +37,20 @@ import { * description: DestinationCalendar was not found * patch: * summary: Edit an existing destination calendar - * consumes: - * - application/json + * parameters: - * - in: body - * name: destinationCalendar - * description: The destinationCalendar to edit - * schema: - * type: object - * $ref: '#/components/schemas/DestinationCalendar' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the destination calendar to edit - * security: - * - ApiKeyAuth: [] + * tags: * - destination-calendars * responses: * 201: * description: OK, destinationCalendar edited successfuly - * model: DestinationCalendar * 400: * description: Bad request. DestinationCalendar body is invalid. * 401: @@ -75,14 +64,12 @@ import { * type: integer * required: true * description: Numeric ID of the destination calendar to delete - * security: - * - ApiKeyAuth: [] + * tags: * - destination-calendars * responses: * 201: * description: OK, destinationCalendar removed successfuly - * model: DestinationCalendar * 400: * description: Bad request. DestinationCalendar id is invalid. * 401: diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts index d7921491c9..cf33e0fa58 100644 --- a/pages/api/destination-calendars/index.ts +++ b/pages/api/destination-calendars/index.ts @@ -14,8 +14,7 @@ import { * /destination-calendars: * get: * summary: Find all destination calendars - * security: - * - ApiKeyAuth: [] + * tags: * - destination-calendars * responses: @@ -27,14 +26,12 @@ import { * description: No destination calendars were found * post: * summary: Creates a new destination calendar - * security: - * - ApiKeyAuth: [] + * tags: * - destination-calendars * responses: * 201: * description: OK, destination calendar created - * model: DestinationCalendar * 400: * description: Bad request. DestinationCalendar body is invalid. * 401: diff --git a/pages/api/docs.ts b/pages/api/docs.ts index 7dd7afa65d..356967d4a2 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -20,26 +20,9 @@ const swaggerHandler = withSwagger({ }, components: { securitySchemes: { ApiKeyAuth: { type: "apiKey", in: "query", name: "apiKey" } }, - security: { ApiKeyAuth: [] }, - schemas: { ...jsonSchema.definitions }, }, + security: [{ apiKey: [] }], }, apiFolder: "pages/api", - tags: [ - "users", - "teams", - "memeberships", - "selected-calendars", - "schedules", - "payments", - "event-types", - "event-type-custom-inputs", - "destination-calendars", - "daily-event-references", - "booking-references", - "availabilities", - "attendees", - ], - sort: true, }); export default swaggerHandler(); diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/event-type-custom-inputs/[id].ts index 7d3ffa7a5d..6760e4b39c 100644 --- a/pages/api/event-type-custom-inputs/[id].ts +++ b/pages/api/event-type-custom-inputs/[id].ts @@ -25,8 +25,7 @@ import { * type: integer * required: true * description: Numeric ID of the eventTypeCustomInput to get - * security: - * - ApiKeyAuth: [] + * tags: * - event-type-custom-inputs * responses: @@ -35,35 +34,25 @@ import { * 401: * description: Authorization information is missing or invalid. * 404: - * deCustomInputscription: EventType was not found + * description: EventType was not found * patch: * summary: Edit an existing eventTypeCustomInput - * consumes: - * - application/json + * parameters: - * - in: body - * name: eventTypeCustomInput - * description: The eventTypeCustomInput to edit - * schema: - * type: object - * $ref: '#/components/schemas/EventTypeCustomInput' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the eventTypeCustomInput to edit - * security: - * - ApiKeyAuth: [] + * tags: * - event-type-custom-inputs * responses: * 201: * description: OK, eventTypeCustomInput edited successfuly - * model: EventTypeCustomInput * 400: - * desCustomInputcription: Bad request. EventType body is invalid. + * description: Bad request. EventType body is invalid. * 401: * description: Authorization information is missing or invalid. * delete: @@ -75,16 +64,14 @@ import { * type: integer * required: true * description: Numeric ID of the eventTypeCustomInput to delete - * security: - * - ApiKeyAuth: [] + * tags: * - event-type-custom-inputs * responses: * 201: * description: OK, eventTypeCustomInput removed successfuly - * model: EventTypeCustomInput * 400: - * desCustomInputcription: Bad request. EventType id is invalid. + * description: Bad request. EventType id is invalid. * 401: * description: Authorization information is missing or invalid. */ diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/event-type-custom-inputs/index.ts index 01f5af921f..e7cc037cd9 100644 --- a/pages/api/event-type-custom-inputs/index.ts +++ b/pages/api/event-type-custom-inputs/index.ts @@ -14,8 +14,7 @@ import { * /event-type-custom-inputs: * get: * summary: Find all eventTypeCustomInputs - * security: - * - ApiKeyAuth: [] + * tags: * - event-type-custom-inputs * responses: @@ -27,14 +26,12 @@ import { * description: No eventTypeCustomInputs were found * post: * summary: Creates a new eventTypeCustomInput - * security: - * - ApiKeyAuth: [] + * tags: * - event-type-custom-inputs * responses: * 201: * description: OK, eventTypeCustomInput created - * model: EventTypeCustomInput * 400: * description: Bad request. EventTypeCustomInput body is invalid. * 401: diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts index 37a5b38be7..ebb440bd37 100644 --- a/pages/api/event-types/[id].ts +++ b/pages/api/event-types/[id].ts @@ -37,16 +37,7 @@ import { * description: EventType was not found * patch: * summary: Edit an existing eventType - * consumes: - * - application/json * parameters: - * - in: body - * name: eventType - * description: The eventType to edit - * schema: - * type: object - * $ref: '#/components/schemas/EventType' - * required: true * - in: path * name: id * schema: @@ -62,7 +53,6 @@ import { * responses: * 201: * description: OK, eventType edited successfuly - * model: EventType * 400: * description: Bad request. EventType body is invalid. * 401: @@ -85,7 +75,6 @@ import { * responses: * 201: * description: OK, eventType removed successfuly - * model: EventType * 400: * description: Bad request. EventType id is invalid. * 401: diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 9e1e83c038..eb6c7d1290 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -11,8 +11,7 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validatio * /event-types: * get: * summary: Find all event types - * security: - * - ApiKeyAuth: [] + * tags: * - event-types * externalDocs: @@ -26,8 +25,7 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validatio * description: No event types were found * post: * summary: Creates a new event type - * security: - * - ApiKeyAuth: [] + * tags: * - event-types * externalDocs: @@ -35,7 +33,6 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validatio * responses: * 201: * description: OK, event type created - * model: EventType * 400: * description: Bad request. EventType body is invalid. * 401: diff --git a/pages/api/index.ts b/pages/api/index.ts index 3f72b7eaef..94461cedce 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -1,10 +1,5 @@ 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" }); } diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts index 0e7498d16c..3172428ec3 100644 --- a/pages/api/memberships/[id].ts +++ b/pages/api/memberships/[id].ts @@ -25,8 +25,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: integer * required: true * description: Numeric teamId of the membership to get - * security: - * - ApiKeyAuth: [] + * tags: * - memberships * responses: @@ -38,16 +37,8 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * description: Membership was not found * patch: * summary: Edit an existing membership - * consumes: - * - application/json + * parameters: - * - in: body - * name: membership - * description: The membership to edit - * schema: - * type: object - * $ref: '#/components/schemas/Membership' - * required: true * - in: path * name: userId * schema: @@ -60,14 +51,12 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: integer * required: true * description: Numeric teamId of the membership to get - * security: - * - ApiKeyAuth: [] + * tags: * - memberships * responses: * 201: * description: OK, membership edited successfuly - * model: Membership * 400: * description: Bad request. Membership body is invalid. * 401: @@ -87,14 +76,12 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: integer * required: true * description: Numeric teamId of the membership to get - * security: - * - ApiKeyAuth: [] + * tags: * - memberships * responses: * 201: * description: OK, membership removed successfuly - * model: Membership * 400: * description: Bad request. Membership id is invalid. * 401: diff --git a/pages/api/memberships/index.ts b/pages/api/memberships/index.ts index 3df3b56d13..78072dd68d 100644 --- a/pages/api/memberships/index.ts +++ b/pages/api/memberships/index.ts @@ -11,8 +11,7 @@ import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validat * /memberships: * get: * summary: Find all memberships - * security: - * - ApiKeyAuth: [] + * tags: * - memberships * responses: @@ -24,14 +23,12 @@ import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validat * description: No memberships were found * post: * summary: Creates a new membership - * security: - * - ApiKeyAuth: [] + * tags: * - memberships * responses: * 201: * description: OK, membership created - * model: Membership * 400: * description: Bad request. Membership body is invalid. * 401: diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts index 8ab4d5eab9..9f0d8315dd 100644 --- a/pages/api/payments/[id].ts +++ b/pages/api/payments/[id].ts @@ -22,8 +22,7 @@ import { * type: integer * required: true * description: Numeric ID of the payment to get - * security: - * - ApiKeyAuth: [] + * tags: * - payments * responses: diff --git a/pages/api/payments/index.ts b/pages/api/payments/index.ts index db0cd349ca..5d16b911df 100644 --- a/pages/api/payments/index.ts +++ b/pages/api/payments/index.ts @@ -11,8 +11,7 @@ import { schemaPaymentPublic } from "@lib/validations/payment"; * /payments: * get: * summary: Find all payments - * security: - * - ApiKeyAuth: [] + * tags: * - payments * responses: diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts index 8a08128f4f..a2d9da0366 100644 --- a/pages/api/schedules/[id].ts +++ b/pages/api/schedules/[id].ts @@ -22,8 +22,7 @@ import { * type: integer * required: true * description: Numeric ID of the schedule to get - * security: - * - ApiKeyAuth: [] + * tags: * - schedules * responses: @@ -35,30 +34,21 @@ import { * description: Schedule was not found * patch: * summary: Edit an existing schedule - * consumes: - * - application/json + * parameters: - * - in: body - * name: schedule - * description: The schedule to edit - * schema: - * type: object - * $ref: '#/components/schemas/Schedule' - * required: true + * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the schedule to edit - * security: - * - ApiKeyAuth: [] + * tags: * - schedules * responses: * 201: * description: OK, schedule edited successfuly - * model: Schedule * 400: * description: Bad request. Schedule body is invalid. * 401: @@ -72,14 +62,12 @@ import { * type: integer * required: true * description: Numeric ID of the schedule to delete - * security: - * - ApiKeyAuth: [] + * tags: * - schedules * responses: * 201: * description: OK, schedule removed successfuly - * model: Schedule * 400: * description: Bad request. Schedule id is invalid. * 401: diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts index 228599eef3..29fe160340 100644 --- a/pages/api/schedules/index.ts +++ b/pages/api/schedules/index.ts @@ -11,8 +11,7 @@ import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations * /schedules: * get: * summary: Find all schedules - * security: - * - ApiKeyAuth: [] + * tags: * - schedules * responses: @@ -24,14 +23,12 @@ import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations * description: No schedules were found * post: * summary: Creates a new schedule - * security: - * - ApiKeyAuth: [] + * tags: * - schedules * responses: * 201: * description: OK, schedule created - * model: Schedule * 400: * description: Bad request. Schedule body is invalid. * 401: diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts index 6efbca86ee..b3df3b88b2 100644 --- a/pages/api/selected-calendars/[id].ts +++ b/pages/api/selected-calendars/[id].ts @@ -34,8 +34,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: string * required: true * description: integration of the selected calendar to get - * security: - * - ApiKeyAuth: [] + * tags: * - selected-calendars * responses: @@ -47,16 +46,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * description: SelectedCalendar was not found * patch: * summary: Edit an existing selected calendar - * consumes: - * - application/json * parameters: - * - in: body - * name: selected-calendar - * description: The selected-calendar to edit - * schema: - * type: object - * $ref: '#/components/schemas/SelectedCalendar' - * required: true * - in: path * name: userId * schema: @@ -75,14 +65,12 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: string * required: true * description: integration of the selected calendar to get - * security: - * - ApiKeyAuth: [] + * tags: * - selected-calendars * responses: * 201: * description: OK, selected-calendar edited successfuly - * model: SelectedCalendar * 400: * description: Bad request. SelectedCalendar body is invalid. * 401: @@ -108,14 +96,12 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: string * required: true * description: integration of the selected calendar to get - * security: - * - ApiKeyAuth: [] + * tags: * - selected-calendars * responses: * 201: * description: OK, selected-calendar removed successfuly - * model: SelectedCalendar * 400: * description: Bad request. SelectedCalendar id is invalid. * 401: diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts index 83537208ba..055ae51346 100644 --- a/pages/api/selected-calendars/index.ts +++ b/pages/api/selected-calendars/index.ts @@ -14,8 +14,7 @@ import { * /selected-calendars: * get: * summary: Find all selected calendars - * security: - * - ApiKeyAuth: [] + * tags: * - selected-calendars * responses: @@ -27,14 +26,12 @@ import { * description: No selected calendars were found * post: * summary: Creates a new selected calendar - * security: - * - ApiKeyAuth: [] + * tags: * - selected-calendars * responses: * 201: * description: OK, selected calendar created - * model: SelectedCalendar * 400: * description: Bad request. SelectedCalendar body is invalid. * 401: diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts index 0fead8e066..9fb11b5e50 100644 --- a/pages/api/teams/[id].ts +++ b/pages/api/teams/[id].ts @@ -22,8 +22,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * type: integer * required: true * description: Numeric ID of the team to get - * security: - * - ApiKeyAuth: [] + * tags: * - teams * responses: @@ -33,36 +32,27 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * description: Authorization information is missing or invalid. * 404: * description: Team was not found + * patch: * summary: Edit an existing team - * consumes: - * - application/json * parameters: - * - in: body - * name: team - * description: The team to edit - * schema: - * type: object - * $ref: '#/components/schemas/Team' - * required: true * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the team to edit - * security: - * - ApiKeyAuth: [] + * tags: * - teams * responses: * 201: * description: OK, team edited successfuly - * model: Team * 400: * description: Bad request. Team body is invalid. * 401: * description: Authorization information is missing or invalid. + * delete: * summary: Remove an existing team * parameters: @@ -72,14 +62,12 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * type: integer * required: true * description: Numeric ID of the team to delete - * security: - * - ApiKeyAuth: [] + * tags: * - teams * responses: * 201: * description: OK, team removed successfuly - * model: Team * 400: * description: Bad request. Team id is invalid. * 401: diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.ts index ce335fff9d..11d646f70f 100644 --- a/pages/api/teams/index.ts +++ b/pages/api/teams/index.ts @@ -12,8 +12,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * /teams: * get: * summary: Find all teams - * security: - * - ApiKeyAuth: [] + * tags: * - teams * responses: @@ -25,14 +24,12 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * description: No teams were found * post: * summary: Creates a new team - * security: - * - ApiKeyAuth: [] + * tags: * - teams * responses: * 201: * description: OK, team created - * model: Team * 400: * description: Bad request. Team body is invalid. * 401: diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts index 06e5612dd0..f8aed85d7d 100644 --- a/pages/api/users/[id].ts +++ b/pages/api/users/[id].ts @@ -22,8 +22,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * type: integer * required: true * description: Numeric ID of the user to get - * security: - * - ApiKeyAuth: [] + * tags: * - users * responses: @@ -35,28 +34,20 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * description: User was not found * patch: * summary: Edit an existing user - * consumes: - * - application/json + * parameters: - * - in: body - * name: name - * description: The users full name - * schema: - * type: string * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the user to edit - * security: - * - ApiKeyAuth: [] + * tags: * - users * responses: * 201: * description: OK, user edited successfuly - * model: User * 400: * description: Bad request. User body is invalid. * 401: @@ -70,14 +61,12 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * type: integer * required: true * description: Numeric ID of the user to delete - * security: - * - ApiKeyAuth: [] + * tags: * - users * responses: * 201: * description: OK, user removed successfuly - * model: User * 400: * description: Bad request. User id is invalid. * 401: diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index fa28b36f5e..c5dfd71b68 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -11,8 +11,7 @@ import { schemaUserReadPublic } from "@lib/validations/user"; * /users: * get: * summary: Find all users (admin only), returns your user if regular user. - * security: - * - ApiKeyAuth: [] + * tags: * - users * responses: diff --git a/templates/endpoints/[id]/delete.ts b/templates/endpoints/[id]/delete.ts index 9c5c6f9f7c..908e74b7d5 100644 --- a/templates/endpoints/[id]/delete.ts +++ b/templates/endpoints/[id]/delete.ts @@ -21,14 +21,12 @@ import { * type: integer * required: true * description: Numeric ID of the resource to delete - * security: - * - ApiKeyAuth: [] + * tags: * - resources * responses: * 201: * description: OK, resource removed successfuly - * model: Resource * 400: * description: Bad request. Resource id is invalid. * 401: diff --git a/templates/endpoints/[id]/edit.ts b/templates/endpoints/[id]/edit.ts index 8ddad4601d..43cb6c8f8e 100644 --- a/templates/endpoints/[id]/edit.ts +++ b/templates/endpoints/[id]/edit.ts @@ -22,14 +22,12 @@ import { * type: integer * required: true * description: Numeric ID of the resource to edit - * security: - * - ApiKeyAuth: [] + * tags: * - resources * responses: * 201: * description: OK, resource edited successfuly - * model: Resource * 400: * description: Bad request. Resource body is invalid. * 401: diff --git a/templates/endpoints/[id]/index.ts b/templates/endpoints/[id]/index.ts index 9f4c64f11d..c3297459ac 100644 --- a/templates/endpoints/[id]/index.ts +++ b/templates/endpoints/[id]/index.ts @@ -22,8 +22,7 @@ import { * type: integer * required: true * description: Numeric ID of the resource to get - * security: - * - ApiKeyAuth: [] + * tags: * - resources * responses: diff --git a/templates/endpoints/get_all.ts b/templates/endpoints/get_all.ts index ee66e7c773..e925133346 100644 --- a/templates/endpoints/get_all.ts +++ b/templates/endpoints/get_all.ts @@ -11,8 +11,7 @@ import { schemaResourcePublic } from "@lib/validations/resource"; * /v1/resources: * get: * summary: Find all resources - * security: - * - ApiKeyAuth: [] + * tags: * - resources * responses: diff --git a/templates/endpoints/get_all_and_post.ts b/templates/endpoints/get_all_and_post.ts index 2ce4b8dfe9..d20075e52c 100644 --- a/templates/endpoints/get_all_and_post.ts +++ b/templates/endpoints/get_all_and_post.ts @@ -11,8 +11,7 @@ import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/p * /v1/payments: * get: * summary: Find all payments - * security: - * - ApiKeyAuth: [] + * tags: * - payments * responses: @@ -24,14 +23,12 @@ import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/p * description: No payments were found * post: * summary: Creates a new payment - * security: - * - ApiKeyAuth: [] + * tags: * - payments * responses: * 201: * description: OK, payment created - * model: Payment * 400: * description: Bad request. Payment body is invalid. * 401: diff --git a/templates/endpoints/post.ts b/templates/endpoints/post.ts index 999bce39c1..3f5b7403d7 100644 --- a/templates/endpoints/post.ts +++ b/templates/endpoints/post.ts @@ -18,14 +18,12 @@ import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } fro * application/json: * schema: * $ref: '#/components/schemas/Resource' - * security: - * - ApiKeyAuth: [] + * tags: * - resources * responses: * 201: * description: OK, resource created - * model: Resource * 400: * description: Bad request. Resource body is invalid. * 401: From d6c34a8e51d6d9a380affc7ab5886ddb97b94c38 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 01:54:21 +0200 Subject: [PATCH 02/11] fix: remove empty lines --- pages/api/attendees/[id].ts | 3 --- pages/api/attendees/index.ts | 2 -- pages/api/availabilities/[id].ts | 3 --- pages/api/availabilities/index.ts | 2 -- pages/api/booking-references/[id].ts | 3 --- pages/api/booking-references/index.ts | 3 --- pages/api/bookings/[id].ts | 4 ---- pages/api/bookings/index.ts | 2 -- pages/api/daily-event-references/[id].ts | 4 ---- pages/api/daily-event-references/index.ts | 2 -- pages/api/destination-calendars/[id].ts | 3 --- pages/api/destination-calendars/index.ts | 2 -- pages/api/event-type-custom-inputs/[id].ts | 4 ---- pages/api/event-type-custom-inputs/index.ts | 2 -- pages/api/event-types/index.ts | 2 -- pages/api/memberships/[id].ts | 4 ---- pages/api/memberships/index.ts | 2 -- pages/api/payments/[id].ts | 1 - pages/api/payments/index.ts | 1 - pages/api/schedules/[id].ts | 5 ----- pages/api/selected-calendars/[id].ts | 2 -- pages/api/selected-calendars/index.ts | 2 -- pages/api/teams/[id].ts | 5 ----- pages/api/teams/index.ts | 2 -- pages/api/users/[id].ts | 4 ---- pages/api/users/index.ts | 1 - 26 files changed, 70 deletions(-) diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index b27c2e40fb..3d6d16c9a1 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -23,7 +23,6 @@ import { * required: true * description: Numeric ID of the attendee to get * example: 3 - * tags: * - attendees * responses: @@ -65,7 +64,6 @@ import { * example: 3 * required: true * description: Numeric ID of the attendee to edit - * tags: * - attendees * responses: @@ -84,7 +82,6 @@ import { * type: integer * required: true * description: Numeric ID of the attendee to delete - * tags: * - attendees * responses: diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.ts index a0514bb8df..262f7a0e0c 100644 --- a/pages/api/attendees/index.ts +++ b/pages/api/attendees/index.ts @@ -11,7 +11,6 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v * /attendees: * get: * summary: Find all attendees - * tags: * - attendees * responses: @@ -23,7 +22,6 @@ import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/v * description: No attendees were found * post: * summary: Creates a new attendee - * requestBody: * description: Create a new attendee related to one of your bookings * required: true diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts index ad6826a6d3..21348a990c 100644 --- a/pages/api/availabilities/[id].ts +++ b/pages/api/availabilities/[id].ts @@ -25,7 +25,6 @@ import { * type: integer * required: true * description: Numeric ID of the availability to get - * tags: * - availabilities * externalDocs: @@ -46,7 +45,6 @@ import { * type: integer * required: true * description: Numeric ID of the availability to edit - * tags: * - availabilities * externalDocs: @@ -67,7 +65,6 @@ import { * type: integer * required: true * description: Numeric ID of the availability to delete - * tags: * - availabilities * externalDocs: diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts index 7d8f18eac3..7ef5e65b8b 100644 --- a/pages/api/availabilities/index.ts +++ b/pages/api/availabilities/index.ts @@ -14,7 +14,6 @@ import { * /availabilities: * get: * summary: Find all availabilities - * tags: * - availabilities * externalDocs: @@ -28,7 +27,6 @@ import { * description: No availabilities were found * post: * summary: Creates a new availability - * tags: * - availabilities * externalDocs: diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index 4014707eb4..cba249df5a 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -26,7 +26,6 @@ import { * type: integer * required: true * description: Numeric ID of the booking reference to get - * tags: * - booking-references * responses: @@ -38,7 +37,6 @@ import { * description: BookingReference was not found * patch: * summary: Edit an existing booking reference - * parameters: * - in: path * name: id @@ -46,7 +44,6 @@ import { * type: integer * required: true * description: Numeric ID of the booking reference to edit - * tags: * - booking-references * responses: diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts index c214b305db..7bd47a56f5 100644 --- a/pages/api/booking-references/index.ts +++ b/pages/api/booking-references/index.ts @@ -14,7 +14,6 @@ import { * /booking-references: * get: * summary: Find all booking references - * tags: * - booking-references * responses: @@ -26,13 +25,11 @@ import { * description: No booking references were found * post: * summary: Creates a new booking reference - * tags: * - booking-references * responses: * 201: * description: OK, booking reference created - * 400: * description: Bad request. BookingReference body is invalid. * 401: diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts index 9c1b647b20..ddfa7a34ce 100644 --- a/pages/api/bookings/[id].ts +++ b/pages/api/bookings/[id].ts @@ -22,7 +22,6 @@ import { * type: integer * required: true * description: Numeric ID of the booking to get - * tags: * - bookings * responses: @@ -34,7 +33,6 @@ import { * description: Booking was not found * patch: * summary: Edit an existing booking - * parameters: * - in: path * name: id @@ -42,7 +40,6 @@ import { * type: integer * required: true * description: Numeric ID of the booking to edit - * tags: * - bookings * responses: @@ -61,7 +58,6 @@ import { * type: integer * required: true * description: Numeric ID of the booking to delete - * tags: * - bookings * responses: diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 311a79b4dd..444fda9488 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -11,7 +11,6 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val * /bookings: * get: * summary: Find all bookings - * tags: * - bookings * responses: @@ -23,7 +22,6 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val * description: No bookings were found * post: * summary: Creates a new booking - * tags: * - bookings * responses: diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/daily-event-references/[id].ts index a59beeebbf..7f1b026e5c 100644 --- a/pages/api/daily-event-references/[id].ts +++ b/pages/api/daily-event-references/[id].ts @@ -25,7 +25,6 @@ import { * type: integer * required: true * description: Numeric ID of the daily event reference to get - * tags: * - daily-event-references * responses: @@ -37,7 +36,6 @@ import { * description: DailyEventReference was not found * patch: * summary: Edit an existing daily event reference - * parameters: * - in: path * name: id @@ -45,7 +43,6 @@ import { * type: integer * required: true * description: Numeric ID of the daily event reference to edit - * tags: * - daily-event-references * responses: @@ -64,7 +61,6 @@ import { * type: integer * required: true * description: Numeric ID of the daily event reference to delete - * tags: * - daily-event-references * responses: diff --git a/pages/api/daily-event-references/index.ts b/pages/api/daily-event-references/index.ts index 290469f307..c129eef677 100644 --- a/pages/api/daily-event-references/index.ts +++ b/pages/api/daily-event-references/index.ts @@ -14,7 +14,6 @@ import { * /daily-event-references: * get: * summary: Find all daily event reference - * tags: * - daily-event-references * responses: @@ -26,7 +25,6 @@ import { * description: No daily event references were found * post: * summary: Creates a new daily event reference - * tags: * - daily-event-references * responses: diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts index ecfe646b09..679dcd5d29 100644 --- a/pages/api/destination-calendars/[id].ts +++ b/pages/api/destination-calendars/[id].ts @@ -25,7 +25,6 @@ import { * type: integer * required: true * description: Numeric ID of the destination calendar to get - * tags: * - destination-calendars * responses: @@ -37,7 +36,6 @@ import { * description: DestinationCalendar was not found * patch: * summary: Edit an existing destination calendar - * parameters: * - in: path * name: id @@ -45,7 +43,6 @@ import { * type: integer * required: true * description: Numeric ID of the destination calendar to edit - * tags: * - destination-calendars * responses: diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts index cf33e0fa58..81a3d36c97 100644 --- a/pages/api/destination-calendars/index.ts +++ b/pages/api/destination-calendars/index.ts @@ -14,7 +14,6 @@ import { * /destination-calendars: * get: * summary: Find all destination calendars - * tags: * - destination-calendars * responses: @@ -26,7 +25,6 @@ import { * description: No destination calendars were found * post: * summary: Creates a new destination calendar - * tags: * - destination-calendars * responses: diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/event-type-custom-inputs/[id].ts index 6760e4b39c..0d84a2a6fb 100644 --- a/pages/api/event-type-custom-inputs/[id].ts +++ b/pages/api/event-type-custom-inputs/[id].ts @@ -25,7 +25,6 @@ import { * type: integer * required: true * description: Numeric ID of the eventTypeCustomInput to get - * tags: * - event-type-custom-inputs * responses: @@ -37,7 +36,6 @@ import { * description: EventType was not found * patch: * summary: Edit an existing eventTypeCustomInput - * parameters: * - in: path * name: id @@ -45,7 +43,6 @@ import { * type: integer * required: true * description: Numeric ID of the eventTypeCustomInput to edit - * tags: * - event-type-custom-inputs * responses: @@ -64,7 +61,6 @@ import { * type: integer * required: true * description: Numeric ID of the eventTypeCustomInput to delete - * tags: * - event-type-custom-inputs * responses: diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/event-type-custom-inputs/index.ts index e7cc037cd9..ac6c0f94cb 100644 --- a/pages/api/event-type-custom-inputs/index.ts +++ b/pages/api/event-type-custom-inputs/index.ts @@ -14,7 +14,6 @@ import { * /event-type-custom-inputs: * get: * summary: Find all eventTypeCustomInputs - * tags: * - event-type-custom-inputs * responses: @@ -26,7 +25,6 @@ import { * description: No eventTypeCustomInputs were found * post: * summary: Creates a new eventTypeCustomInput - * tags: * - event-type-custom-inputs * responses: diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index eb6c7d1290..4030e84186 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -11,7 +11,6 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validatio * /event-types: * get: * summary: Find all event types - * tags: * - event-types * externalDocs: @@ -25,7 +24,6 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validatio * description: No event types were found * post: * summary: Creates a new event type - * tags: * - event-types * externalDocs: diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts index 3172428ec3..fa4c298be4 100644 --- a/pages/api/memberships/[id].ts +++ b/pages/api/memberships/[id].ts @@ -25,7 +25,6 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: integer * required: true * description: Numeric teamId of the membership to get - * tags: * - memberships * responses: @@ -37,7 +36,6 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * description: Membership was not found * patch: * summary: Edit an existing membership - * parameters: * - in: path * name: userId @@ -51,7 +49,6 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: integer * required: true * description: Numeric teamId of the membership to get - * tags: * - memberships * responses: @@ -76,7 +73,6 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: integer * required: true * description: Numeric teamId of the membership to get - * tags: * - memberships * responses: diff --git a/pages/api/memberships/index.ts b/pages/api/memberships/index.ts index 78072dd68d..137eaf48ac 100644 --- a/pages/api/memberships/index.ts +++ b/pages/api/memberships/index.ts @@ -11,7 +11,6 @@ import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validat * /memberships: * get: * summary: Find all memberships - * tags: * - memberships * responses: @@ -23,7 +22,6 @@ import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validat * description: No memberships were found * post: * summary: Creates a new membership - * tags: * - memberships * responses: diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts index 9f0d8315dd..90882e760c 100644 --- a/pages/api/payments/[id].ts +++ b/pages/api/payments/[id].ts @@ -22,7 +22,6 @@ import { * type: integer * required: true * description: Numeric ID of the payment to get - * tags: * - payments * responses: diff --git a/pages/api/payments/index.ts b/pages/api/payments/index.ts index 5d16b911df..0c6eae0f85 100644 --- a/pages/api/payments/index.ts +++ b/pages/api/payments/index.ts @@ -11,7 +11,6 @@ import { schemaPaymentPublic } from "@lib/validations/payment"; * /payments: * get: * summary: Find all payments - * tags: * - payments * responses: diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts index a2d9da0366..d6645597a6 100644 --- a/pages/api/schedules/[id].ts +++ b/pages/api/schedules/[id].ts @@ -22,7 +22,6 @@ import { * type: integer * required: true * description: Numeric ID of the schedule to get - * tags: * - schedules * responses: @@ -34,16 +33,13 @@ import { * description: Schedule was not found * patch: * summary: Edit an existing schedule - * parameters: - * - in: path * name: id * schema: * type: integer * required: true * description: Numeric ID of the schedule to edit - * tags: * - schedules * responses: @@ -62,7 +58,6 @@ import { * type: integer * required: true * description: Numeric ID of the schedule to delete - * tags: * - schedules * responses: diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts index b3df3b88b2..a8e1e7ab15 100644 --- a/pages/api/selected-calendars/[id].ts +++ b/pages/api/selected-calendars/[id].ts @@ -34,7 +34,6 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: string * required: true * description: integration of the selected calendar to get - * tags: * - selected-calendars * responses: @@ -65,7 +64,6 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/ * type: string * required: true * description: integration of the selected calendar to get - * tags: * - selected-calendars * responses: diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts index 055ae51346..c6e1b122d9 100644 --- a/pages/api/selected-calendars/index.ts +++ b/pages/api/selected-calendars/index.ts @@ -14,7 +14,6 @@ import { * /selected-calendars: * get: * summary: Find all selected calendars - * tags: * - selected-calendars * responses: @@ -26,7 +25,6 @@ import { * description: No selected calendars were found * post: * summary: Creates a new selected calendar - * tags: * - selected-calendars * responses: diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts index 9fb11b5e50..0368a69f5c 100644 --- a/pages/api/teams/[id].ts +++ b/pages/api/teams/[id].ts @@ -22,7 +22,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * type: integer * required: true * description: Numeric ID of the team to get - * tags: * - teams * responses: @@ -32,7 +31,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * description: Authorization information is missing or invalid. * 404: * description: Team was not found - * patch: * summary: Edit an existing team * parameters: @@ -42,7 +40,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * type: integer * required: true * description: Numeric ID of the team to edit - * tags: * - teams * responses: @@ -52,7 +49,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * description: Bad request. Team body is invalid. * 401: * description: Authorization information is missing or invalid. - * delete: * summary: Remove an existing team * parameters: @@ -62,7 +58,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * type: integer * required: true * description: Numeric ID of the team to delete - * tags: * - teams * responses: diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.ts index 11d646f70f..e5ae852dd8 100644 --- a/pages/api/teams/index.ts +++ b/pages/api/teams/index.ts @@ -12,7 +12,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * /teams: * get: * summary: Find all teams - * tags: * - teams * responses: @@ -24,7 +23,6 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * description: No teams were found * post: * summary: Creates a new team - * tags: * - teams * responses: diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts index f8aed85d7d..4cea26e8e3 100644 --- a/pages/api/users/[id].ts +++ b/pages/api/users/[id].ts @@ -22,7 +22,6 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * type: integer * required: true * description: Numeric ID of the user to get - * tags: * - users * responses: @@ -34,7 +33,6 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * description: User was not found * patch: * summary: Edit an existing user - * parameters: * - in: path * name: id @@ -42,7 +40,6 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * type: integer * required: true * description: Numeric ID of the user to edit - * tags: * - users * responses: @@ -61,7 +58,6 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * type: integer * required: true * description: Numeric ID of the user to delete - * tags: * - users * responses: diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index c5dfd71b68..4ef860e18f 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -11,7 +11,6 @@ import { schemaUserReadPublic } from "@lib/validations/user"; * /users: * get: * summary: Find all users (admin only), returns your user if regular user. - * tags: * - users * responses: From e13ea234b84578a716bab7702060028b2386bb9d Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 02:30:59 +0200 Subject: [PATCH 03/11] fix: improve docs in attendees availabilities and booking references --- pages/api/attendees/[id].ts | 180 ++++++++++++++------------ pages/api/attendees/index.ts | 114 ++++++++-------- pages/api/availabilities/[id].ts | 146 +++++++++++---------- pages/api/availabilities/index.ts | 70 +++++----- pages/api/booking-references/[id].ts | 132 +++++++++---------- pages/api/booking-references/index.ts | 60 ++++----- 6 files changed, 360 insertions(+), 342 deletions(-) diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index 3d6d16c9a1..01ae4f5449 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -10,90 +10,10 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /attendees/{id}: - * get: - * summary: Find an attendee by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the attendee to get - * example: 3 - * tags: - * - attendees - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Attendee was not found - * patch: - * summary: Edit an existing attendee - * 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@example.com - * name: - * type: string - * example: John Doe - * timeZone: - * type: string - * example: Europe/London - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * example: 3 - * required: true - * description: Numeric ID of the attendee to edit - * tags: - * - attendees - * responses: - * 201: - * description: OK, attendee edited successfuly - * 400: - * description: Bad request. Attendee body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing attendee - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the attendee to delete - * tags: - * - attendees - * responses: - * 201: - * description: OK, attendee removed successfuly - * 400: - * description: Bad request. Attendee id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function attendeeById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body, userId } = req; +export async function attendeeById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); if (!safeQuery.success) { res.status(400).json({ error: safeQuery.error }); @@ -109,6 +29,29 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse ) { - const { method, userId } = req; - // Here we make sure to only return attendee's of the user's own bookings. const userBookings = await prisma.booking.findMany({ where: { userId, @@ -73,6 +20,21 @@ async function createOrlistAllAttendees( }); const attendees = userBookings.map((booking) => booking.attendees).flat(); if (method === "GET") { + /** + * @swagger + * /attendees: + * get: + * summary: Find all attendees + * tags: + * - attendees + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No attendees were found + */ if (attendees) res.status(200).json({ attendees }); else (error: Error) => @@ -81,13 +43,51 @@ async function createOrlistAllAttendees( error, }); } else if (method === "POST") { - const safePost = schemaAttendeeCreateBodyParams.safeParse(req.body); + /** + * @swagger + * /attendees: + * post: + * summary: Creates a new attendee + * 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@example.com + * name: + * type: string + * example: John Doe + * timeZone: + * type: string + * example: Europe/London + * tags: + * - attendees + * responses: + * 201: + * description: OK, attendee created + * 400: + * description: Bad request. Attendee body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safePost = schemaAttendeeCreateBodyParams.safeParse(body); if (!safePost.success) { - console.log(safePost.error); res.status(400).json({ error: safePost.error }); throw new Error("Invalid request body", safePost.error); } - const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts index 21348a990c..de131eb0ff 100644 --- a/pages/api/availabilities/[id].ts +++ b/pages/api/availabilities/[id].ts @@ -13,80 +13,41 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /availabilities/{id}: - * get: - * summary: Find an availability by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the availability to get - * tags: - * - availabilities - * externalDocs: - * url: https://docs.cal.com/availability - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Availability was not found - * patch: - * summary: Edit an existing availability - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the availability to edit - * tags: - * - availabilities - * externalDocs: - * url: https://docs.cal.com/availability - * responses: - * 201: - * description: OK, availability edited successfuly - * 400: - * description: Bad request. Availability body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing availability - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the availability to delete - * tags: - * - availabilities - * externalDocs: - * url: https://docs.cal.com/availability - * responses: - * 201: - * description: OK, availability removed successfuly - * 400: - * description: Bad request. Availability id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function availabilityById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +export async function availabilityById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const data = await prisma.availability.findMany({ where: { userId } }); const availabiltiesIds = data.map((availability) => availability.id); if (!availabiltiesIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { + /** + * @swagger + * /availabilities/{id}: + * get: + * summary: Find an availability by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the availability to get + * tags: + * - availabilities + * externalDocs: + * url: https://docs.cal.com/availability + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Availability was not found + */ case "GET": await prisma.availability .findUnique({ where: { id: safeQuery.data.id } }) @@ -96,7 +57,30 @@ export async function availabilityById(req: NextApiRequest, res: NextApiResponse res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error }) ); break; - + /** + * @swagger + * /availabilities/{id}: + * patch: + * summary: Edit an existing availability + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the availability to edit + * tags: + * - availabilities + * externalDocs: + * url: https://docs.cal.com/availability + * responses: + * 201: + * description: OK, availability edited successfuly + * 400: + * description: Bad request. Availability body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "PATCH": const safeBody = schemaAvailabilityEditBodyParams.safeParse(body); if (!safeBody.success) throw new Error("Invalid request body"); @@ -115,14 +99,36 @@ export async function availabilityById(req: NextApiRequest, res: NextApiResponse .then((data) => schemaAvailabilityReadPublic.parse(data)) .then((availability) => res.status(200).json({ availability })) .catch((error: Error) => { - console.log(error); res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error, }); }); break; - + /** + * @swagger + * /availabilities/{id}: + * delete: + * summary: Remove an existing availability + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the availability to delete + * tags: + * - availabilities + * externalDocs: + * url: https://docs.cal.com/availability + * responses: + * 201: + * description: OK, availability removed successfuly + * 400: + * description: Bad request. Availability id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "DELETE": await prisma.availability .delete({ where: { id: safeQuery.data.id } }) diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts index 7ef5e65b8b..25b0866071 100644 --- a/pages/api/availabilities/index.ts +++ b/pages/api/availabilities/index.ts @@ -9,44 +9,28 @@ import { schemaAvailabilityReadPublic, } from "@lib/validations/availability"; -/** - * @swagger - * /availabilities: - * get: - * summary: Find all availabilities - * tags: - * - availabilities - * externalDocs: - * url: https://docs.cal.com/availability - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No availabilities were found - * post: - * summary: Creates a new availability - * tags: - * - availabilities - * externalDocs: - * url: https://docs.cal.com/availability - * responses: - * 201: - * description: OK, availability created - * 400: - * description: Bad request. Availability body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ async function createOrlistAllAvailabilities( - req: NextApiRequest, + { method, userId }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; - if (method === "GET") { + /** + * @swagger + * /availabilities: + * get: + * summary: Find all availabilities + * tags: + * - availabilities + * externalDocs: + * url: https://docs.cal.com/availability + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No availabilities were found + */ const data = await prisma.availability.findMany({ where: { userId } }); const availabilities = data.map((availability) => schemaAvailabilityReadPublic.parse(availability)); if (availabilities) res.status(200).json({ availabilities }); @@ -57,11 +41,27 @@ async function createOrlistAllAvailabilities( error, }); } else if (method === "POST") { + /** + * @swagger + * /availabilities: + * post: + * summary: Creates a new availability + * tags: + * - availabilities + * externalDocs: + * url: https://docs.cal.com/availability + * responses: + * 201: + * description: OK, availability created + * 400: + * description: Bad request. Availability body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ const safe = schemaAvailabilityCreateBodyParams.safeParse(req.body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.availability.create({ data: { ...safe.data, userId } }); - console.log(data); const availability = schemaAvailabilityReadPublic.parse(data); if (availability) res.status(201).json({ availability, message: "Availability created successfully" }); diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index cba249df5a..bbc2ea6fa2 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -14,73 +14,12 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /booking-references/{id}: - * get: - * summary: Find a booking reference by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking reference to get - * tags: - * - booking-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: BookingReference was not found - * patch: - * summary: Edit an existing booking reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking reference to edit - * tags: - * - booking-references - * responses: - * 201: - * description: OK, bookingReference edited successfuly - * 400: - * description: Bad request. BookingReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing booking reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking reference to delete - - * tags: - * - booking-references - * responses: - * 201: - * description: OK, bookingReference removed successfuly - * 400: - * description: Bad request. BookingReference id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ export async function bookingReferenceById( - req: NextApiRequest, + { method, query, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method, query, body } = req; const safeQuery = schemaQueryIdParseInt.safeParse(query); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, @@ -91,6 +30,28 @@ export async function bookingReferenceById( if (!bookingReference) throw new Error("BookingReference not found"); if (userBookingIds.includes(bookingReference.bookingId)) { switch (method) { + /** + * @swagger + * /booking-references/{id}: + * get: + * summary: Find a booking reference by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking reference to get + * tags: + * - booking-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: BookingReference was not found + */ case "GET": await prisma.bookingReference .findUnique({ where: { id: safeQuery.data.id } }) @@ -103,10 +64,30 @@ export async function bookingReferenceById( }) ); break; - + /** + * @swagger + * /booking-references/{id}: + * patch: + * summary: Edit an existing booking reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking reference to edit + * tags: + * - booking-references + * responses: + * 201: + * description: OK, bookingReference edited successfuly + * 400: + * description: Bad request. BookingReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "PATCH": const safeBody = schemaBookingEditBodyParams.safeParse(body); - if (!safeBody.success) { throw new Error("Invalid request body"); } @@ -121,7 +102,28 @@ export async function bookingReferenceById( }) ); break; - + /** + * @swagger + * /booking-references/{id}: + * delete: + * summary: Remove an existing booking reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking reference to delete + * tags: + * - booking-references + * responses: + * 201: + * description: OK, bookingReference removed successfuly + * 400: + * description: Bad request. BookingReference id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "DELETE": await prisma.bookingReference .delete({ diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts index 7bd47a56f5..a4ced04215 100644 --- a/pages/api/booking-references/index.ts +++ b/pages/api/booking-references/index.ts @@ -9,38 +9,10 @@ import { schemaBookingReferenceReadPublic, } from "@lib/validations/booking-reference"; -/** - * @swagger - * /booking-references: - * get: - * summary: Find all booking references - * tags: - * - booking-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No booking references were found - * post: - * summary: Creates a new booking reference - * tags: - * - booking-references - * responses: - * 201: - * description: OK, booking reference created - * 400: - * description: Bad request. BookingReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ async function createOrlistAllBookingReferences( - req: NextApiRequest, + { method, userId }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, @@ -48,6 +20,21 @@ async function createOrlistAllBookingReferences( if (!userWithBookings) throw new Error("User not found"); const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat(); if (method === "GET") { + /** + * @swagger + * /booking-references: + * get: + * summary: Find all booking references + * tags: + * - booking-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No booking references were found + */ const data = await prisma.bookingReference.findMany({ where: { id: { in: userBookingIds } } }); const booking_references = data.map((bookingReference) => schemaBookingReferenceReadPublic.parse(bookingReference) @@ -60,6 +47,21 @@ async function createOrlistAllBookingReferences( error, }); } else if (method === "POST") { + /** + * @swagger + * /booking-references: + * post: + * summary: Creates a new booking reference + * tags: + * - booking-references + * responses: + * 201: + * description: OK, booking reference created + * 400: + * description: Bad request. BookingReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ const safe = schemaBookingCreateBodyParams.safeParse(req.body); if (!safe.success) { throw new Error("Invalid request body"); From d06a9488e4a339fba17d56f3639727bd2d967dcc Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 02:49:38 +0200 Subject: [PATCH 04/11] fix: rename endpoints to be only 2 words max --- README.md | 4 +- pages/api/attendees/[id].ts | 24 ++-- pages/api/bookings/[id].ts | 127 +++++++++--------- pages/api/bookings/index.ts | 42 +++--- .../[id].ts | 8 +- .../index.ts | 6 +- .../[id].ts | 124 +++++++++-------- .../index.ts | 6 +- 8 files changed, 184 insertions(+), 157 deletions(-) rename pages/api/{event-type-custom-inputs => custom-inputs}/[id].ts (97%) rename pages/api/{event-type-custom-inputs => custom-inputs}/index.ts (97%) rename pages/api/{daily-event-references => event-references}/[id].ts (61%) rename pages/api/{daily-event-references => event-references}/index.ts (96%) diff --git a/README.md b/README.md index 17082202cd..a9904ac3ff 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,9 @@ We aim to provide a fully tested API for our peace of mind, this is accomplished | attendees | ✅ | ✅ | ✅ | ✅ | ✅ | | availabilities | ✅ | ✅ | ✅ | ✅ | ✅ | | booking-references | ✅ | ✅ | ✅ | ✅ | ✅ | -| daily-event-references | ✅ | ✅ | ✅ | ✅ | ✅ | +| event-references | ✅ | ✅ | ✅ | ✅ | ✅ | | destination-calendars | ✅ | ✅ | ✅ | ✅ | ✅ | -| event-type-custom-inputs | ✅ | ✅ | ✅ | ✅ | ✅ | +| custom-inputs | ✅ | ✅ | ✅ | ✅ | ✅ | | event-types | ✅ | ✅ | ✅ | ✅ | ✅ | | memberships | ✅ | ✅ | ✅ | ✅ | ✅ | | payments | ✅ | ✅ | ❌ | ❌ | ❌ | diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index 01ae4f5449..b0bf73796f 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -19,14 +19,22 @@ export async function attendeeById( res.status(400).json({ error: safeQuery.error }); throw new Error("Invalid request query", safeQuery.error); } - const userBookings = await prisma.booking.findMany({ - where: { userId }, - include: { attendees: true }, - }); - const attendees = userBookings.map((booking) => booking.attendees).flat(); - const attendeeIds = attendees.map((attendee) => attendee.id); - // Here we make sure to only return attendee's of the user's own bookings. - if (!attendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); + const userBookingsAttendeeIds = await prisma.booking + // Find all user bookings, including attendees + .findMany({ + where: { userId }, + include: { attendees: true }, + }) + .then( + // Flatten and merge all the attendees in one array + (bookings) => + bookings + .map((bookings) => bookings.attendees) // Get the attendees IDs from user bookings + .flat() // Needed to flatten the array of arrays of all bookings attendees + .map((attendee) => attendee.id) // We only need the attendee IDs + ); + // @note: Here we make sure to only return attendee's of the user's own bookings. + if (!userBookingsAttendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { /** diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts index ddfa7a34ce..0974bd55b1 100644 --- a/pages/api/bookings/[id].ts +++ b/pages/api/bookings/[id].ts @@ -10,64 +10,6 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /bookings/{id}: - * get: - * summary: Find a booking by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking to get - * tags: - * - bookings - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Booking was not found - * patch: - * summary: Edit an existing booking - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking to edit - * tags: - * - bookings - * responses: - * 201: - * description: OK, booking edited successfuly - * 400: - * description: Bad request. Booking body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing booking - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking to delete - * tags: - * - bookings - * responses: - * 201: - * description: OK, booking removed successfuly - * 400: - * description: Bad request. Booking id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ export async function bookingById(req: NextApiRequest, res: NextApiResponse) { const { method, query, body } = req; const safeQuery = schemaQueryIdParseInt.safeParse(query); @@ -82,6 +24,28 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse +) { + const { method } = req; + const userId = req.userId; + + if (method === "GET") { + /** * @swagger * /bookings: @@ -20,6 +29,21 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val * description: Authorization information is missing or invalid. * 404: * description: No bookings were found + */ + const data = await prisma.booking.findMany({ where: { userId } }); + const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking)); + if (bookings) res.status(200).json({ bookings }); + else + (error: Error) => + res.status(404).json({ + message: "No Bookings were found", + error, + }); + } else if (method === "POST") { + +/** + * @swagger + * /bookings: * post: * summary: Creates a new booking * tags: @@ -32,24 +56,6 @@ import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/val * 401: * description: Authorization information is missing or invalid. */ -async function createOrlistAllBookings( - req: NextApiRequest, - res: NextApiResponse -) { - const { method } = req; - const userId = req.userId; - - if (method === "GET") { - const data = await prisma.booking.findMany({ where: { userId } }); - const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking)); - if (bookings) res.status(200).json({ bookings }); - else - (error: Error) => - res.status(404).json({ - message: "No Bookings were found", - error, - }); - } else if (method === "POST") { const safe = schemaBookingCreateBodyParams.safeParse(req.body); if (!safe.success) throw new Error("Invalid request body"); diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/custom-inputs/[id].ts similarity index 97% rename from pages/api/event-type-custom-inputs/[id].ts rename to pages/api/custom-inputs/[id].ts index 0d84a2a6fb..2860d9a525 100644 --- a/pages/api/event-type-custom-inputs/[id].ts +++ b/pages/api/custom-inputs/[id].ts @@ -15,7 +15,7 @@ import { /** * @swagger - * /event-type-custom-inputs/{id}: + * /custom-inputs/{id}: * get: * summary: Find a eventTypeCustomInput by ID * parameters: @@ -26,7 +26,7 @@ import { * required: true * description: Numeric ID of the eventTypeCustomInput to get * tags: - * - event-type-custom-inputs + * - custom-inputs * responses: * 200: * description: OK @@ -44,7 +44,7 @@ import { * required: true * description: Numeric ID of the eventTypeCustomInput to edit * tags: - * - event-type-custom-inputs + * - custom-inputs * responses: * 201: * description: OK, eventTypeCustomInput edited successfuly @@ -62,7 +62,7 @@ import { * required: true * description: Numeric ID of the eventTypeCustomInput to delete * tags: - * - event-type-custom-inputs + * - custom-inputs * responses: * 201: * description: OK, eventTypeCustomInput removed successfuly diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/custom-inputs/index.ts similarity index 97% rename from pages/api/event-type-custom-inputs/index.ts rename to pages/api/custom-inputs/index.ts index ac6c0f94cb..ee1232d83c 100644 --- a/pages/api/event-type-custom-inputs/index.ts +++ b/pages/api/custom-inputs/index.ts @@ -11,11 +11,11 @@ import { /** * @swagger - * /event-type-custom-inputs: + * /custom-inputs: * get: * summary: Find all eventTypeCustomInputs * tags: - * - event-type-custom-inputs + * - custom-inputs * responses: * 200: * description: OK @@ -26,7 +26,7 @@ import { * post: * summary: Creates a new eventTypeCustomInput * tags: - * - event-type-custom-inputs + * - custom-inputs * responses: * 201: * description: OK, eventTypeCustomInput created diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/event-references/[id].ts similarity index 61% rename from pages/api/daily-event-references/[id].ts rename to pages/api/event-references/[id].ts index 7f1b026e5c..d0a31fcf11 100644 --- a/pages/api/daily-event-references/[id].ts +++ b/pages/api/event-references/[id].ts @@ -13,64 +13,6 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /daily-event-references/{id}: - * get: - * summary: Find a daily event reference by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the daily event reference to get - * tags: - * - daily-event-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: DailyEventReference was not found - * patch: - * summary: Edit an existing daily event reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the daily event reference to edit - * tags: - * - daily-event-references - * responses: - * 201: - * description: OK, dailyEventReference edited successfuly - * 400: - * description: Bad request. DailyEventReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing daily event reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the daily event reference to delete - * tags: - * - daily-event-references - * responses: - * 201: - * description: OK, dailyEventReference removed successfuly - * 400: - * description: Bad request. DailyEventReference id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ export async function dailyEventReferenceById( req: NextApiRequest, res: NextApiResponse @@ -92,6 +34,28 @@ export async function dailyEventReferenceById( res.status(401).json({ message: "Unauthorized" }); else { switch (method) { + /** + * @swagger + * /event-references/{id}: + * get: + * summary: Find a event reference by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the event reference to get + * tags: + * - event-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: EventReference was not found + */ case "GET": await prisma.dailyEventReference .findUnique({ where: { id: safeQuery.data.id } }) @@ -105,6 +69,28 @@ export async function dailyEventReferenceById( ); break; + /** + * @swagger + * /event-references/{id}: + * patch: + * summary: Edit an existing event reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the event reference to edit + * tags: + * - event-references + * responses: + * 201: + * description: OK, EventReference edited successfuly + * 400: + * description: Bad request. EventReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "PATCH": if (!safeBody.success) { throw new Error("Invalid request body"); @@ -121,6 +107,28 @@ export async function dailyEventReferenceById( ); break; + /** + * @swagger + * /event-references/{id}: + * delete: + * summary: Remove an existing event reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the event reference to delete + * tags: + * - event-references + * responses: + * 201: + * description: OK, EventReference removed successfuly + * 400: + * description: Bad request. EventReference id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "DELETE": await prisma.dailyEventReference .delete({ diff --git a/pages/api/daily-event-references/index.ts b/pages/api/event-references/index.ts similarity index 96% rename from pages/api/daily-event-references/index.ts rename to pages/api/event-references/index.ts index c129eef677..1168ccbda6 100644 --- a/pages/api/daily-event-references/index.ts +++ b/pages/api/event-references/index.ts @@ -11,11 +11,11 @@ import { /** * @swagger - * /daily-event-references: + * /event-references: * get: * summary: Find all daily event reference * tags: - * - daily-event-references + * - event-references * responses: * 200: * description: OK @@ -26,7 +26,7 @@ import { * post: * summary: Creates a new daily event reference * tags: - * - daily-event-references + * - event-references * responses: * 201: * description: OK, daily event reference created From 9bb0f82075998477a8872b4ad021d208ef4e8574 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 17:29:57 +0200 Subject: [PATCH 05/11] fix: improve comments, no anys --- pages/api/attendees/[id].ts | 2 +- pages/api/attendees/index.ts | 2 +- pages/api/availabilities/[id].ts | 2 +- pages/api/booking-references/[id].ts | 4 +- pages/api/booking-references/index.ts | 10 +- pages/api/bookings/[id].ts | 11 +- pages/api/bookings/index.ts | 67 ++++---- pages/api/custom-inputs/[id].ts | 9 +- pages/api/custom-inputs/index.ts | 65 ++++---- pages/api/destination-calendars/[id].ts | 167 +++++++++++-------- pages/api/destination-calendars/index.ts | 63 ++++---- pages/api/event-references/[id].ts | 8 +- pages/api/event-references/index.ts | 62 +++---- pages/api/event-types/[id].ts | 159 +++++++++--------- pages/api/event-types/index.ts | 71 ++++---- pages/api/memberships/[id].ts | 169 ++++++++++--------- pages/api/memberships/index.ts | 62 +++---- pages/api/payments/[id].ts | 10 +- pages/api/schedules/[id].ts | 124 +++++++------- pages/api/schedules/index.ts | 58 +++---- pages/api/selected-calendars/[id].ts | 198 ++++++++++++----------- pages/api/selected-calendars/index.ts | 72 +++++---- pages/api/teams/[id].ts | 2 +- pages/api/users/[id].ts | 2 +- templates/endpoints/[id]/index.ts | 2 +- 25 files changed, 742 insertions(+), 659 deletions(-) diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index b0bf73796f..4e044790a4 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -41,7 +41,7 @@ export async function attendeeById( * @swagger * /attendees/{id}: * get: - * summary: Find an attendee by ID + * summary: Find an attendee * parameters: * - in: path * name: id diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.ts index 4f57b8e9b7..18bbce51d7 100644 --- a/pages/api/attendees/index.ts +++ b/pages/api/attendees/index.ts @@ -95,7 +95,7 @@ async function createOrlistAllAttendees( if (!userWithBookings) { throw new Error("User not found"); } - const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat(); + const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); // Here we make sure to only return attendee's of the user's own bookings. if (!userBookingIds.includes(safePost.data.bookingId)) res.status(401).json({ message: "Unauthorized" }); else { diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts index de131eb0ff..139e36e22f 100644 --- a/pages/api/availabilities/[id].ts +++ b/pages/api/availabilities/[id].ts @@ -28,7 +28,7 @@ export async function availabilityById( * @swagger * /availabilities/{id}: * get: - * summary: Find an availability by ID + * summary: Find an availability * parameters: * - in: path * name: id diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index bbc2ea6fa2..cb0358d901 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -25,7 +25,7 @@ export async function bookingReferenceById( include: { bookings: true }, }); if (!userWithBookings) throw new Error("User not found"); - const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat(); + const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); const bookingReference = await prisma.bookingReference.findUnique({ where: { id: safeQuery.data.id } }); if (!bookingReference) throw new Error("BookingReference not found"); if (userBookingIds.includes(bookingReference.bookingId)) { @@ -34,7 +34,7 @@ export async function bookingReferenceById( * @swagger * /booking-references/{id}: * get: - * summary: Find a booking reference by ID + * summary: Find a booking reference * parameters: * - in: path * name: id diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts index a4ced04215..87cbe25cdc 100644 --- a/pages/api/booking-references/index.ts +++ b/pages/api/booking-references/index.ts @@ -10,7 +10,7 @@ import { } from "@lib/validations/booking-reference"; async function createOrlistAllBookingReferences( - { method, userId }: NextApiRequest, + { method, userId, body }: NextApiRequest, res: NextApiResponse ) { const userWithBookings = await prisma.user.findUnique({ @@ -18,7 +18,7 @@ async function createOrlistAllBookingReferences( include: { bookings: true }, }); if (!userWithBookings) throw new Error("User not found"); - const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat(); + const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); if (method === "GET") { /** * @swagger @@ -62,13 +62,11 @@ async function createOrlistAllBookingReferences( * 401: * description: Authorization information is missing or invalid. */ - const safe = schemaBookingCreateBodyParams.safeParse(req.body); + const safe = schemaBookingCreateBodyParams.safeParse(body); if (!safe.success) { throw new Error("Invalid request body"); } - // const booking_reference = schemaBookingReferencePublic.parse(data); - const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, @@ -76,7 +74,7 @@ async function createOrlistAllBookingReferences( if (!userWithBookings) { throw new Error("User not found"); } - const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat(); + const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); if (!userBookingIds.includes(safe.data.bookingId)) res.status(401).json({ message: "Unauthorized" }); else { const booking_reference = await prisma.bookingReference.create({ diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts index 0974bd55b1..21fdd9a937 100644 --- a/pages/api/bookings/[id].ts +++ b/pages/api/bookings/[id].ts @@ -10,17 +10,18 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -export async function bookingById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +export async function bookingById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, }); if (!userWithBookings) throw new Error("User not found"); - const userBookingIds = userWithBookings.bookings.map((booking: any) => booking.id).flat(); + const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); if (!userBookingIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { @@ -28,7 +29,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; - if (method === "GET") { - -/** - * @swagger - * /bookings: - * get: - * summary: Find all bookings - * tags: - * - bookings - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No bookings were found - */ + /** + * @swagger + * /bookings: + * get: + * summary: Find all bookings + * tags: + * - bookings + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No bookings were found + */ const data = await prisma.booking.findMany({ where: { userId } }); const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking)); if (bookings) res.status(200).json({ bookings }); @@ -40,22 +36,21 @@ async function createOrlistAllBookings( error, }); } else if (method === "POST") { - -/** - * @swagger - * /bookings: - * post: - * summary: Creates a new booking - * tags: - * - bookings - * responses: - * 201: - * description: OK, booking created - * 400: - * description: Bad request. Booking body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ + /** + * @swagger + * /bookings: + * post: + * summary: Creates a new booking + * tags: + * - bookings + * responses: + * 201: + * description: OK, booking created + * 400: + * description: Bad request. Booking body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ const safe = schemaBookingCreateBodyParams.safeParse(req.body); if (!safe.success) throw new Error("Invalid request body"); diff --git a/pages/api/custom-inputs/[id].ts b/pages/api/custom-inputs/[id].ts index 2860d9a525..3339f31027 100644 --- a/pages/api/custom-inputs/[id].ts +++ b/pages/api/custom-inputs/[id].ts @@ -17,7 +17,7 @@ import { * @swagger * /custom-inputs/{id}: * get: - * summary: Find a eventTypeCustomInput by ID + * summary: Find a eventTypeCustomInput * parameters: * - in: path * name: id @@ -71,12 +71,13 @@ import { * 401: * description: Authorization information is missing or invalid. */ -async function eventTypeById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +async function eventTypeById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaEventTypeCustomInputBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const data = await prisma.eventType.findMany({ where: { userId } }); const userEventTypes = data.map((eventType) => eventType.id); const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({ diff --git a/pages/api/custom-inputs/index.ts b/pages/api/custom-inputs/index.ts index ee1232d83c..c7d5f9df90 100644 --- a/pages/api/custom-inputs/index.ts +++ b/pages/api/custom-inputs/index.ts @@ -9,42 +9,28 @@ import { schemaEventTypeCustomInputPublic, } from "@lib/validations/event-type-custom-input"; -/** - * @swagger - * /custom-inputs: - * get: - * summary: Find all eventTypeCustomInputs - * tags: - * - custom-inputs - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No eventTypeCustomInputs were found - * post: - * summary: Creates a new eventTypeCustomInput - * tags: - * - custom-inputs - * responses: - * 201: - * description: OK, eventTypeCustomInput created - * 400: - * description: Bad request. EventTypeCustomInput body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ async function createOrlistAllEventTypeCustomInputs( - req: NextApiRequest, + { userId, method, body }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; const data = await prisma.eventType.findMany({ where: { userId } }); - const userEventTypes = data.map((eventType) => eventType.id); - + const userEventTypes: number[] = data.map((eventType) => eventType.id); if (method === "GET") { + /** + * @swagger + * /custom-inputs: + * get: + * summary: Find all eventTypeCustomInputs + * tags: + * - custom-inputs + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No eventTypeCustomInputs were found + */ const data = await prisma.eventTypeCustomInput.findMany({ where: { eventType: userEventTypes } }); const event_type_custom_inputs = data.map((eventTypeCustomInput) => schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput) @@ -57,7 +43,22 @@ async function createOrlistAllEventTypeCustomInputs( error, }); } else if (method === "POST") { - const safe = schemaEventTypeCustomInputBodyParams.safeParse(req.body); + /** + * @swagger + * /custom-inputs: + * post: + * summary: Creates a new eventTypeCustomInput + * tags: + * - custom-inputs + * responses: + * 201: + * description: OK, eventTypeCustomInput created + * 400: + * description: Bad request. EventTypeCustomInput body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safe = schemaEventTypeCustomInputBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); // Since we're supporting a create or connect relation on eventType, we need to treat them differently // When using connect on event type, check if userId is the owner of the event diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts index 679dcd5d29..f5d187eb25 100644 --- a/pages/api/destination-calendars/[id].ts +++ b/pages/api/destination-calendars/[id].ts @@ -13,74 +13,13 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /destination-calendars/{id}: - * get: - * summary: Find a destination calendar by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the destination calendar to get - * tags: - * - destination-calendars - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: DestinationCalendar was not found - * patch: - * summary: Edit an existing destination calendar - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the destination calendar to edit - * tags: - * - destination-calendars - * responses: - * 201: - * description: OK, destinationCalendar edited successfuly - * 400: - * description: Bad request. DestinationCalendar body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing destination calendar - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the destination calendar to delete - - * tags: - * - destination-calendars - * responses: - * 201: - * description: OK, destinationCalendar removed successfuly - * 400: - * description: Bad request. DestinationCalendar id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ export async function destionationCalendarById( - req: NextApiRequest, + { method, query, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method, query, body } = req; const safeQuery = schemaQueryIdParseInt.safeParse(query); 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 } }); const userDestinationCalendars = data.map((destinationCalendar) => destinationCalendar.id); // FIXME: Should we also check ownership of bokingId and eventTypeId to avoid users cross-pollinating other users calendars. @@ -88,6 +27,64 @@ export async function destionationCalendarById( if (userDestinationCalendars.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { + /** + * @swagger + * /destination-calendars/{id}: + * get: + * summary: Find a destination calendar + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to get + * tags: + * - destination-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: DestinationCalendar was not found + * patch: + * summary: Edit an existing destination calendar + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to edit + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destinationCalendar edited successfuly + * 400: + * description: Bad request. DestinationCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing destination calendar + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to delete + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destinationCalendar removed successfuly + * 400: + * description: Bad request. DestinationCalendar id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "GET": await prisma.destinationCalendar .findUnique({ where: { id: safeQuery.data.id } }) @@ -100,7 +97,28 @@ export async function destionationCalendarById( }) ); break; - + /** + * @swagger + * /destination-calendars/{id}: + * patch: + * summary: Edit an existing destination calendar + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to edit + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destinationCalendar edited successfuly + * 400: + * description: Bad request. DestinationCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "PATCH": if (!safeBody.success) { throw new Error("Invalid request body"); @@ -116,7 +134,28 @@ export async function destionationCalendarById( }) ); break; - + /** + * @swagger + * /destination-calendars/{id}: + * delete: + * summary: Remove an existing destination calendar + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to delete + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destinationCalendar removed successfuly + * 400: + * description: Bad request. DestinationCalendar id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "DELETE": await prisma.destinationCalendar .delete({ diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts index 81a3d36c97..4006a67c72 100644 --- a/pages/api/destination-calendars/index.ts +++ b/pages/api/destination-calendars/index.ts @@ -9,40 +9,26 @@ import { schemaDestinationCalendarReadPublic, } from "@lib/validations/destination-calendar"; -/** - * @swagger - * /destination-calendars: - * get: - * summary: Find all destination calendars - * tags: - * - destination-calendars - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No destination calendars were found - * post: - * summary: Creates a new destination calendar - * tags: - * - destination-calendars - * responses: - * 201: - * description: OK, destination calendar created - * 400: - * description: Bad request. DestinationCalendar body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ async function createOrlistAllDestinationCalendars( - req: NextApiRequest, + { method, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; - if (method === "GET") { + /** + * @swagger + * /destination-calendars: + * get: + * summary: Find all destination calendars + * tags: + * - destination-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No destination calendars were found + */ const data = await prisma.destinationCalendar.findMany({ where: { userId } }); const destination_calendars = data.map((destinationCalendar) => schemaDestinationCalendarReadPublic.parse(destinationCalendar) @@ -55,7 +41,22 @@ async function createOrlistAllDestinationCalendars( error, }); } else if (method === "POST") { - const safe = schemaDestinationCalendarCreateBodyParams.safeParse(req.body); + /** + * @swagger + * /destination-calendars: + * post: + * summary: Creates a new destination calendar + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destination calendar created + * 400: + * description: Bad request. DestinationCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safe = schemaDestinationCalendarCreateBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.destinationCalendar.create({ data: { ...safe.data, userId } }); diff --git a/pages/api/event-references/[id].ts b/pages/api/event-references/[id].ts index d0a31fcf11..a98d5f74e9 100644 --- a/pages/api/event-references/[id].ts +++ b/pages/api/event-references/[id].ts @@ -14,16 +14,14 @@ import { } from "@lib/validations/shared/queryIdTransformParseInt"; export async function dailyEventReferenceById( - req: NextApiRequest, + { method, query, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method, query, body } = req; const safeQuery = schemaQueryIdParseInt.safeParse(query); 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 } }); - const userBookingIds = userBookings.map((booking) => booking.id); + const userBookingIds: number[] = userBookings.map((booking) => booking.id); const userBookingDailyEventReferences = await prisma.dailyEventReference.findMany({ where: { bookingId: { in: userBookingIds } }, }); @@ -38,7 +36,7 @@ export async function dailyEventReferenceById( * @swagger * /event-references/{id}: * get: - * summary: Find a event reference by ID + * summary: Find a event reference * parameters: * - in: path * name: id diff --git a/pages/api/event-references/index.ts b/pages/api/event-references/index.ts index 1168ccbda6..bc19171de8 100644 --- a/pages/api/event-references/index.ts +++ b/pages/api/event-references/index.ts @@ -9,42 +9,29 @@ import { schemaDailyEventReferenceReadPublic, } from "@lib/validations/daily-event-reference"; -/** - * @swagger - * /event-references: - * get: - * summary: Find all daily event reference - * tags: - * - event-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No daily event references were found - * post: - * summary: Creates a new daily event reference - * tags: - * - event-references - * responses: - * 201: - * description: OK, daily event reference created - * 400: - * description: Bad request. DailyEventReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ async function createOrlistAllDailyEventReferences( - req: NextApiRequest, + { method, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; const userBookings = await prisma.booking.findMany({ where: { userId } }); const userBookingIds = userBookings.map((booking) => booking.id); if (method === "GET") { + /** + * @swagger + * /event-references: + * get: + * summary: Find all daily event reference + * tags: + * - event-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No daily event references were found + */ const data = await prisma.dailyEventReference.findMany({ where: { bookingId: { in: userBookingIds } }, }); @@ -59,7 +46,22 @@ async function createOrlistAllDailyEventReferences( error, }); } else if (method === "POST") { - const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(req.body); + /** + * @swagger + * /event-references: + * post: + * summary: Creates a new daily event reference + * tags: + * - event-references + * responses: + * 201: + * description: OK, daily event reference created + * 400: + * description: Bad request. DailyEventReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.dailyEventReference.create({ data: safe.data }); diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts index ebb440bd37..0ece116d17 100644 --- a/pages/api/event-types/[id].ts +++ b/pages/api/event-types/[id].ts @@ -10,87 +10,43 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /event-types/{id}: - * get: - * summary: Find a eventType by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventType to get - * security: - * - ApiKeyAuth: [] - * tags: - * - event-types - * externalDocs: - * url: https://docs.cal.com/event-types - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: EventType was not found - * patch: - * summary: Edit an existing eventType - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventType to edit - * security: - * - ApiKeyAuth: [] - * tags: - * - event-types - * externalDocs: - * url: https://docs.cal.com/event-types - * responses: - * 201: - * description: OK, eventType edited successfuly - * 400: - * description: Bad request. EventType body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing eventType - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventType to delete - * security: - * - ApiKeyAuth: [] - * tags: - * - event-types - * externalDocs: - * url: https://docs.cal.com/event-types - * responses: - * 201: - * description: OK, eventType removed successfuly - * 400: - * description: Bad request. EventType id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function eventTypeById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +export async function eventTypeById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); - const safeBody = schemaEventTypeBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const data = await prisma.eventType.findMany({ where: { userId } }); const userEventTypes = data.map((eventType) => eventType.id); if (!userEventTypes.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { + /** + * @swagger + * /event-types/{id}: + * get: + * summary: Find a eventType + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventType to get + * security: + * - ApiKeyAuth: [] + * tags: + * - event-types + * externalDocs: + * url: https://docs.cal.com/event-types + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: EventType was not found + */ case "GET": await prisma.eventType .findUnique({ where: { id: safeQuery.data.id } }) @@ -103,8 +59,34 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; - if (method === "GET") { + /** + * @swagger + * /event-types: + * get: + * summary: Find all event types + * tags: + * - event-types + * externalDocs: + * url: https://docs.cal.com/event-types + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No event types were found + */ const data = await prisma.eventType.findMany({ where: { userId } }); const event_types = data.map((eventType) => schemaEventTypePublic.parse(eventType)); if (event_types) res.status(200).json({ event_types }); @@ -54,7 +38,24 @@ async function createOrlistAllEventTypes( error, }); } else if (method === "POST") { - const safe = schemaEventTypeBodyParams.safeParse(req.body); + /** + * @swagger + * /event-types: + * post: + * summary: Creates a new event type + * tags: + * - event-types + * externalDocs: + * url: https://docs.cal.com/event-types + * responses: + * 201: + * description: OK, event type created + * 400: + * description: Bad request. EventType body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safe = schemaEventTypeBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.eventType.create({ data: { ...safe.data, userId } }); diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts index fa4c298be4..0681a629a9 100644 --- a/pages/api/memberships/[id].ts +++ b/pages/api/memberships/[id].ts @@ -7,93 +7,45 @@ import type { MembershipResponse } from "@lib/types"; import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership"; import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; -/** - * @swagger - * /memberships/{userId}_{teamId}: - * get: - * summary: Find a membership by userID and teamID - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: Numeric userId of the membership to get - * - in: path - * name: teamId - * schema: - * type: integer - * required: true - * description: Numeric teamId of the membership to get - * tags: - * - memberships - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Membership was not found - * patch: - * summary: Edit an existing membership - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: Numeric userId of the membership to get - * - in: path - * name: teamId - * schema: - * type: integer - * required: true - * description: Numeric teamId of the membership to get - * tags: - * - memberships - * responses: - * 201: - * description: OK, membership edited successfuly - * 400: - * description: Bad request. Membership body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing membership - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: Numeric userId of the membership to get - * - in: path - * name: teamId - * schema: - * type: integer - * required: true - * description: Numeric teamId of the membership to get - * tags: - * - memberships - * responses: - * 201: - * description: OK, membership removed successfuly - * 400: - * description: Bad request. Membership id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function membershipById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +export async function membershipById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdAsString.safeParse(query); - const safeBody = schemaMembershipBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); // This is how we set the userId and teamId in the query for managing compoundId. const [paramUserId, teamId] = safeQuery.data.id.split("_"); - const userId = req.userId; if (parseInt(paramUserId) !== userId) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { + /** + * @swagger + * /memberships/{userId}_{teamId}: + * get: + * summary: Find a membership by userID and teamID + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the membership to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the membership to get + * tags: + * - memberships + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Membership was not found + */ case "GET": await prisma.membership .findUnique({ @@ -114,7 +66,36 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; if (method === "GET") { + /** + * @swagger + * /memberships: + * get: + * summary: Find all memberships + * tags: + * - memberships + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No memberships were found + */ const data = await prisma.membership.findMany({ where: { userId } }); const memberships = data.map((membership) => schemaMembershipPublic.parse(membership)); if (memberships) res.status(200).json({ memberships }); @@ -49,7 +36,22 @@ async function createOrlistAllMemberships( error, }); } else if (method === "POST") { - const safe = schemaMembershipBodyParams.safeParse(req.body); + /** + * @swagger + * /memberships: + * post: + * summary: Creates a new membership + * tags: + * - memberships + * responses: + * 201: + * description: OK, membership created + * 400: + * description: Bad request. Membership body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safe = schemaMembershipBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.membership.create({ data: { ...safe.data, userId } }); diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts index 90882e760c..ebcaa0c504 100644 --- a/pages/api/payments/[id].ts +++ b/pages/api/payments/[id].ts @@ -14,7 +14,7 @@ import { * @swagger * /payments/{id}: * get: - * summary: Find one of your own payments by ID + * summary: Find a payment * parameters: * - in: path * name: id @@ -32,11 +32,11 @@ import { * 404: * description: Payment was not found */ -export async function paymentById(req: NextApiRequest, res: NextApiResponse) { - const { method, query } = req; +export async function paymentById( + { method, query, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); - const userId = req.userId; - if (safeQuery.success && method === "GET") { const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts index d6645597a6..af63d8af2b 100644 --- a/pages/api/schedules/[id].ts +++ b/pages/api/schedules/[id].ts @@ -10,64 +10,6 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -/** - * @swagger - * /schedules/{id}: - * get: - * summary: Find a schedule by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the schedule to get - * tags: - * - schedules - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Schedule was not found - * patch: - * summary: Edit an existing schedule - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the schedule to edit - * tags: - * - schedules - * responses: - * 201: - * description: OK, schedule edited successfuly - * 400: - * description: Bad request. Schedule body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing schedule - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the schedule to delete - * tags: - * - schedules - * responses: - * 201: - * description: OK, schedule removed successfuly - * 400: - * description: Bad request. Schedule id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ export async function scheduleById(req: NextApiRequest, res: NextApiResponse) { const { method, query, body } = req; const safeQuery = schemaQueryIdParseInt.safeParse(query); @@ -79,6 +21,28 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse @@ -42,6 +14,21 @@ async function createOrlistAllSchedules( const userId = req.userId; if (method === "GET") { + /** + * @swagger + * /schedules: + * get: + * summary: Find all schedules + * tags: + * - schedules + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No schedules were found + */ const data = await prisma.schedule.findMany({ where: { userId } }); const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule)); if (schedules) res.status(200).json({ schedules }); @@ -52,6 +39,21 @@ async function createOrlistAllSchedules( error, }); } else if (method === "POST") { + /** + * @swagger + * /schedules: + * post: + * summary: Creates a new schedule + * tags: + * - schedules + * responses: + * 201: + * description: OK, schedule created + * 400: + * description: Bad request. Schedule body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ const safe = schemaScheduleBodyParams.safeParse(req.body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.schedule.create({ data: { ...safe.data, userId } }); diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts index a8e1e7ab15..10fb737cf9 100644 --- a/pages/api/selected-calendars/[id].ts +++ b/pages/api/selected-calendars/[id].ts @@ -10,101 +10,6 @@ import { } from "@lib/validations/selected-calendar"; import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; -/** - * @swagger - * /selected-calendars/{userId}_{integration}_{externalId}: - * get: - * summary: Find a selected-calendar by userID and teamID - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: userId of the selected calendar to get - * - in: path - * name: externalId - * schema: - * type: string - * required: true - * description: externalId of the selected calendar to get - * - in: path - * name: integration - * schema: - * type: string - * required: true - * description: integration of the selected calendar to get - * tags: - * - selected-calendars - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: SelectedCalendar was not found - * patch: - * summary: Edit an existing selected calendar - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: userId of the selected calendar to get - * - in: path - * name: externalId - * schema: - * type: string - * required: true - * description: externalId of the selected calendar to get - * - in: path - * name: integration - * schema: - * type: string - * required: true - * description: integration of the selected calendar to get - * tags: - * - selected-calendars - * responses: - * 201: - * description: OK, selected-calendar edited successfuly - * 400: - * description: Bad request. SelectedCalendar body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing selected-calendar - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: userId of the selected calendar to get - * - in: path - * name: externalId - * schema: - * type: integer - * required: true - * description: externalId of the selected-calendar to get - * - in: path - * name: integration - * schema: - * type: string - * required: true - * description: integration of the selected calendar to get - - * tags: - * - selected-calendars - * responses: - * 201: - * description: OK, selected-calendar removed successfuly - * 400: - * description: Bad request. SelectedCalendar id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ export async function selectedCalendarById( req: NextApiRequest, res: NextApiResponse @@ -119,6 +24,40 @@ export async function selectedCalendarById( if (userId !== parseInt(paramUserId)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { + /** + * @swagger + * /selected-calendars/{userId}_{integration}_{externalId}: + * get: + * summary: Find a selected calendar + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: userId of the selected calendar to get + * - in: path + * name: externalId + * schema: + * type: string + * required: true + * description: externalId of the selected calendar to get + * - in: path + * name: integration + * schema: + * type: string + * required: true + * description: integration of the selected calendar to get + * tags: + * - selected-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: SelectedCalendar was not found + */ case "GET": await prisma.selectedCalendar .findUnique({ @@ -140,6 +79,40 @@ export async function selectedCalendarById( ); break; + /** + * @swagger + * /selected-calendars/{userId}_{integration}_{externalId}: + * patch: + * summary: Edit a selected calendar + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: userId of the selected calendar to get + * - in: path + * name: externalId + * schema: + * type: string + * required: true + * description: externalId of the selected calendar to get + * - in: path + * name: integration + * schema: + * type: string + * required: true + * description: integration of the selected calendar to get + * tags: + * - selected-calendars + * responses: + * 201: + * description: OK, selected-calendar edited successfuly + * 400: + * description: Bad request. SelectedCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "PATCH": if (!safeBody.success) { throw new Error("Invalid request body"); @@ -164,7 +137,40 @@ export async function selectedCalendarById( }) ); break; - + /** + * @swagger + * /selected-calendars/{userId}_{integration}_{externalId}: + * delete: + * summary: Remove a selected calendar + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: userId of the selected calendar to get + * - in: path + * name: externalId + * schema: + * type: integer + * required: true + * description: externalId of the selected-calendar to get + * - in: path + * name: integration + * schema: + * type: string + * required: true + * description: integration of the selected calendar to get + * tags: + * - selected-calendars + * responses: + * 201: + * description: OK, selected-calendar removed successfuly + * 400: + * description: Bad request. SelectedCalendar id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ case "DELETE": await prisma.selectedCalendar .delete({ diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts index c6e1b122d9..758d663b8f 100644 --- a/pages/api/selected-calendars/index.ts +++ b/pages/api/selected-calendars/index.ts @@ -9,40 +9,26 @@ import { schemaSelectedCalendarPublic, } from "@lib/validations/selected-calendar"; -/** - * @swagger - * /selected-calendars: - * get: - * summary: Find all selected calendars - * tags: - * - selected-calendars - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No selected calendars were found - * post: - * summary: Creates a new selected calendar - * tags: - * - selected-calendars - * responses: - * 201: - * description: OK, selected calendar created - * 400: - * description: Bad request. SelectedCalendar body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ async function createOrlistAllSelectedCalendars( - req: NextApiRequest, + { method, userId }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; - if (method === "GET") { + /** + * @swagger + * /selected-calendars: + * get: + * summary: Find all selected calendars + * tags: + * - selected-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No selected calendars were found + */ const data = await prisma.selectedCalendar.findMany({ where: { userId } }); const selected_calendars = data.map((selected_calendar) => schemaSelectedCalendarPublic.parse(selected_calendar) @@ -55,6 +41,32 @@ async function createOrlistAllSelectedCalendars( error, }); } else if (method === "POST") { + /** + * @swagger + * /selected-calendars: + * get: + * summary: Find all selected calendars + * tags: + * - selected-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No selected calendars were found + * post: + * summary: Creates a new selected calendar + * tags: + * - selected-calendars + * responses: + * 201: + * description: OK, selected calendar created + * 400: + * description: Bad request. SelectedCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ const safe = schemaSelectedCalendarBodyParams.safeParse(req.body); if (!safe.success) throw new Error("Invalid request body"); // Create new selectedCalendar connecting it to current userId diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts index 0368a69f5c..d3e971d487 100644 --- a/pages/api/teams/[id].ts +++ b/pages/api/teams/[id].ts @@ -14,7 +14,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * @swagger * /teams/{id}: * get: - * summary: Find a team by ID + * summary: Find a team * parameters: * - in: path * name: id diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts index 4cea26e8e3..58d0b41d36 100644 --- a/pages/api/users/[id].ts +++ b/pages/api/users/[id].ts @@ -14,7 +14,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * @swagger * /users/{id}: * get: - * summary: Find a user by ID, returns your user if regular user. + * summary: Find a user, returns your user if regular user. * parameters: * - in: path * name: id diff --git a/templates/endpoints/[id]/index.ts b/templates/endpoints/[id]/index.ts index c3297459ac..c9b1d85152 100644 --- a/templates/endpoints/[id]/index.ts +++ b/templates/endpoints/[id]/index.ts @@ -14,7 +14,7 @@ import { * @swagger * /v1/resources/{id}: * get: - * summary: Find a resource by ID + * summary: Find a resource * parameters: * - in: path * name: id From c8d776aeb7ce1b2f360b14395d802ca9adceba21 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 17:36:25 +0200 Subject: [PATCH 06/11] fix: remove extra comments --- pages/api/attendees/[id].ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index 4e044790a4..9a2e40f106 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -29,9 +29,9 @@ export async function attendeeById( // Flatten and merge all the attendees in one array (bookings) => bookings - .map((bookings) => bookings.attendees) // Get the attendees IDs from user bookings - .flat() // Needed to flatten the array of arrays of all bookings attendees - .map((attendee) => attendee.id) // We only need the attendee IDs + .map((bookings) => bookings.attendees) + .flat() + .map((attendee) => attendee.id) ); // @note: Here we make sure to only return attendee's of the user's own bookings. if (!userBookingsAttendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); From 57aeb19c66a0055943be39472693e56d0396f0a4 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 29 Apr 2022 19:45:33 +0200 Subject: [PATCH 07/11] fix: pass enableCors true to swaggeruireact props doesn't seem to work --- pages/api/docs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/docs.ts b/pages/api/docs.ts index 356967d4a2..e87c6c1f5c 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -21,7 +21,7 @@ const swaggerHandler = withSwagger({ components: { securitySchemes: { ApiKeyAuth: { type: "apiKey", in: "query", name: "apiKey" } }, }, - security: [{ apiKey: [] }], + security: [{ ApiKeyAuth: [] }], }, apiFolder: "pages/api", }); From 4321fec7344498b9874b9480bf203ff6d46379ab Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Sat, 30 Apr 2022 05:09:54 +0200 Subject: [PATCH 08/11] fix: remove json schema --- json-schema/json-schema.json | 1064 ---------------------------------- next.config.js | 10 +- 2 files changed, 3 insertions(+), 1071 deletions(-) delete mode 100644 json-schema/json-schema.json diff --git a/json-schema/json-schema.json b/json-schema/json-schema.json deleted file mode 100644 index f6a197e4a5..0000000000 --- a/json-schema/json-schema.json +++ /dev/null @@ -1,1064 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "EventType": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "title": { - "type": "string", - "description": "@zod.nonempty()" - }, - "slug": { - "type": "string", - "description": "@zod.custom(imports.eventTypeSlug)" - }, - "description": { - "type": ["string", "null"] - }, - "position": { - "type": "integer", - "default": 0 - }, - "locations": { - "type": ["number", "string", "boolean", "object", "array", "null"], - "description": "@zod.custom(imports.eventTypeLocations)" - }, - "length": { - "type": "integer" - }, - "hidden": { - "type": "boolean", - "default": false - }, - "users": { - "type": "array", - "items": { - "$ref": "#/components/schemas/User" - } - }, - "userId": { - "type": ["integer", "null"] - }, - "team": { - "anyOf": [ - { - "$ref": "#/components/schemas/Team" - }, - { - "type": "null" - } - ] - }, - "bookings": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Booking" - } - }, - "availability": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Availability" - } - }, - "webhooks": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Webhook" - } - }, - "destinationCalendar": { - "anyOf": [ - { - "$ref": "#/components/schemas/DestinationCalendar" - }, - { - "type": "null" - } - ] - }, - "eventName": { - "type": ["string", "null"] - }, - "customInputs": { - "type": "array", - "items": { - "$ref": "#/components/schemas/EventTypeCustomInput" - } - }, - "timeZone": { - "type": ["string", "null"] - }, - "periodType": { - "type": "string", - "default": "UNLIMITED", - "enum": ["UNLIMITED", "ROLLING", "RANGE"] - }, - "periodStartDate": { - "type": ["string", "null"], - "format": "date-time" - }, - "periodEndDate": { - "type": ["string", "null"], - "format": "date-time" - }, - "periodDays": { - "type": ["integer", "null"] - }, - "periodCountCalendarDays": { - "type": ["boolean", "null"] - }, - "requiresConfirmation": { - "type": "boolean", - "default": false - }, - "disableGuests": { - "type": "boolean", - "default": false - }, - "minimumBookingNotice": { - "type": "integer", - "default": 120 - }, - "beforeEventBuffer": { - "type": "integer", - "default": 0 - }, - "afterEventBuffer": { - "type": "integer", - "default": 0 - }, - "schedulingType": { - "type": ["string", "null"], - "enum": ["ROUND_ROBIN", "COLLECTIVE"] - }, - "schedule": { - "anyOf": [ - { - "$ref": "#/components/schemas/Schedule" - }, - { - "type": "null" - } - ] - }, - "price": { - "type": "integer", - "default": 0 - }, - "currency": { - "type": "string", - "default": "usd" - }, - "slotInterval": { - "type": ["integer", "null"] - }, - "metadata": { - "type": ["number", "string", "boolean", "object", "array", "null"] - } - } - }, - "Credential": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "type": { - "type": "string" - }, - "key": { - "type": ["number", "string", "boolean", "object", "array", "null"] - }, - "user": { - "anyOf": [ - { - "$ref": "#/components/schemas/User" - }, - { - "type": "null" - } - ] - } - } - }, - "DestinationCalendar": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "integration": { - "type": "string" - }, - "externalId": { - "type": "string" - }, - "user": { - "anyOf": [ - { - "$ref": "#/components/schemas/User" - }, - { - "type": "null" - } - ] - }, - "booking": { - "anyOf": [ - { - "$ref": "#/components/schemas/Booking" - }, - { - "type": "null" - } - ] - }, - "eventType": { - "anyOf": [ - { - "$ref": "#/components/schemas/EventType" - }, - { - "type": "null" - } - ] - } - } - }, - "User": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "username": { - "type": ["string", "null"] - }, - "name": { - "type": ["string", "null"] - }, - "email": { - "type": "string", - "description": "@zod.email()" - }, - "emailVerified": { - "type": ["string", "null"], - "format": "date-time" - }, - "password": { - "type": ["string", "null"] - }, - "bio": { - "type": ["string", "null"] - }, - "avatar": { - "type": ["string", "null"] - }, - "timeZone": { - "type": "string", - "default": "Europe/London" - }, - "weekStart": { - "type": "string", - "default": "Sunday" - }, - "startTime": { - "type": "integer", - "default": 0 - }, - "endTime": { - "type": "integer", - "default": 1440 - }, - "bufferTime": { - "type": "integer", - "default": 0 - }, - "hideBranding": { - "type": "boolean", - "default": false - }, - "theme": { - "type": ["string", "null"] - }, - "createdDate": { - "type": "string", - "format": "date-time" - }, - "trialEndsAt": { - "type": ["string", "null"], - "format": "date-time" - }, - "eventTypes": { - "type": "array", - "items": { - "$ref": "#/components/schemas/EventType" - } - }, - "credentials": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Credential" - } - }, - "teams": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Membership" - } - }, - "bookings": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Booking" - } - }, - "schedules": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Schedule" - } - }, - "defaultScheduleId": { - "type": ["integer", "null"] - }, - "selectedCalendars": { - "type": "array", - "items": { - "$ref": "#/components/schemas/SelectedCalendar" - } - }, - "completedOnboarding": { - "type": "boolean", - "default": false - }, - "locale": { - "type": ["string", "null"] - }, - "timeFormat": { - "type": ["integer", "null"], - "default": 12 - }, - "twoFactorSecret": { - "type": ["string", "null"] - }, - "twoFactorEnabled": { - "type": "boolean", - "default": false - }, - "identityProvider": { - "type": "string", - "default": "CAL", - "enum": ["CAL", "GOOGLE", "SAML"] - }, - "identityProviderId": { - "type": ["string", "null"] - }, - "availability": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Availability" - } - }, - "invitedTo": { - "type": ["integer", "null"] - }, - "plan": { - "type": "string", - "default": "TRIAL", - "enum": ["FREE", "TRIAL", "PRO"] - }, - "webhooks": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Webhook" - } - }, - "brandColor": { - "type": "string", - "default": "#292929" - }, - "darkBrandColor": { - "type": "string", - "default": "#fafafa" - }, - "destinationCalendar": { - "anyOf": [ - { - "$ref": "#/components/schemas/DestinationCalendar" - }, - { - "type": "null" - } - ] - }, - "away": { - "type": "boolean", - "default": false - }, - "metadata": { - "type": ["number", "string", "boolean", "object", "array", "null"] - }, - "verified": { - "type": ["boolean", "null"], - "default": false - }, - "apiKeys": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ApiKey" - } - } - } - }, - "Team": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "name": { - "type": ["string", "null"] - }, - "slug": { - "type": ["string", "null"] - }, - "logo": { - "type": ["string", "null"] - }, - "bio": { - "type": ["string", "null"] - }, - "hideBranding": { - "type": "boolean", - "default": false - }, - "members": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Membership" - } - }, - "eventTypes": { - "type": "array", - "items": { - "$ref": "#/components/schemas/EventType" - } - } - } - }, - "Membership": { - "type": "object", - "properties": { - "accepted": { - "type": "boolean", - "default": false - }, - "role": { - "type": "string", - "enum": ["MEMBER", "ADMIN", "OWNER"] - }, - "team": { - "$ref": "#/components/schemas/Team" - }, - "user": { - "$ref": "#/components/schemas/User" - } - } - }, - "VerificationRequest": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "identifier": { - "type": "string" - }, - "token": { - "type": "string" - }, - "expires": { - "type": "string", - "format": "date-time" - }, - "createdAt": { - "type": "string", - "format": "date-time" - }, - "updatedAt": { - "type": "string", - "format": "date-time" - } - } - }, - "BookingReference": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "type": { - "type": "string" - }, - "uid": { - "type": "string" - }, - "meetingId": { - "type": ["string", "null"] - }, - "meetingPassword": { - "type": ["string", "null"] - }, - "meetingUrl": { - "type": ["string", "null"] - }, - "booking": { - "anyOf": [ - { - "$ref": "#/components/schemas/Booking" - }, - { - "type": "null" - } - ] - } - } - }, - "Attendee": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "email": { - "type": "string" - }, - "name": { - "type": "string" - }, - "timeZone": { - "type": "string" - }, - "locale": { - "type": ["string", "null"], - "default": "en" - }, - "booking": { - "anyOf": [ - { - "$ref": "#/components/schemas/Booking" - }, - { - "type": "null" - } - ] - } - } - }, - "DailyEventReference": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "dailyurl": { - "type": "string", - "default": "dailycallurl" - }, - "dailytoken": { - "type": "string", - "default": "dailytoken" - }, - "booking": { - "anyOf": [ - { - "$ref": "#/components/schemas/Booking" - }, - { - "type": "null" - } - ] - } - } - }, - "Booking": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "uid": { - "type": "string" - }, - "user": { - "anyOf": [ - { - "$ref": "#/components/schemas/User" - }, - { - "type": "null" - } - ] - }, - "references": { - "type": "array", - "items": { - "$ref": "#/components/schemas/BookingReference" - } - }, - "eventType": { - "anyOf": [ - { - "$ref": "#/components/schemas/EventType" - }, - { - "type": "null" - } - ] - }, - "title": { - "type": "string" - }, - "description": { - "type": ["string", "null"] - }, - "startTime": { - "type": "string", - "format": "date-time" - }, - "endTime": { - "type": "string", - "format": "date-time" - }, - "attendees": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Attendee" - } - }, - "location": { - "type": ["string", "null"] - }, - "dailyRef": { - "anyOf": [ - { - "$ref": "#/components/schemas/DailyEventReference" - }, - { - "type": "null" - } - ] - }, - "createdAt": { - "type": "string", - "format": "date-time" - }, - "updatedAt": { - "type": ["string", "null"], - "format": "date-time" - }, - "confirmed": { - "type": "boolean", - "default": true - }, - "rejected": { - "type": "boolean", - "default": false - }, - "status": { - "type": "string", - "default": "ACCEPTED", - "enum": ["CANCELLED", "ACCEPTED", "REJECTED", "PENDING"] - }, - "paid": { - "type": "boolean", - "default": false - }, - "payment": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Payment" - } - }, - "destinationCalendar": { - "anyOf": [ - { - "$ref": "#/components/schemas/DestinationCalendar" - }, - { - "type": "null" - } - ] - }, - "cancellationReason": { - "type": ["string", "null"] - }, - "rejectionReason": { - "type": ["string", "null"] - } - } - }, - "Schedule": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "user": { - "$ref": "#/components/schemas/User" - }, - "eventType": { - "anyOf": [ - { - "$ref": "#/components/schemas/EventType" - }, - { - "type": "null" - } - ] - }, - "name": { - "type": "string" - }, - "timeZone": { - "type": ["string", "null"] - }, - "availability": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Availability" - } - } - } - }, - "Availability": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "user": { - "anyOf": [ - { - "$ref": "#/components/schemas/User" - }, - { - "type": "null" - } - ] - }, - "eventType": { - "anyOf": [ - { - "$ref": "#/components/schemas/EventType" - }, - { - "type": "null" - } - ] - }, - "days": { - "type": "array", - "items": { - "type": "integer" - } - }, - "startTime": { - "type": "string", - "format": "date-time" - }, - "endTime": { - "type": "string", - "format": "date-time" - }, - "date": { - "type": ["string", "null"], - "format": "date-time" - }, - "Schedule": { - "anyOf": [ - { - "$ref": "#/components/schemas/Schedule" - }, - { - "type": "null" - } - ] - } - } - }, - "SelectedCalendar": { - "type": "object", - "properties": { - "user": { - "$ref": "#/components/schemas/User" - }, - "integration": { - "type": "string" - }, - "externalId": { - "type": "string" - } - } - }, - "EventTypeCustomInput": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "eventType": { - "$ref": "#/components/schemas/EventType" - }, - "label": { - "type": "string" - }, - "type": { - "type": "string", - "enum": ["TEXT", "TEXTLONG", "NUMBER", "BOOL"] - }, - "required": { - "type": "boolean" - }, - "placeholder": { - "type": "string", - "default": "" - } - } - }, - "ResetPasswordRequest": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "createdAt": { - "type": "string", - "format": "date-time" - }, - "updatedAt": { - "type": "string", - "format": "date-time" - }, - "email": { - "type": "string" - }, - "expires": { - "type": "string", - "format": "date-time" - } - } - }, - "ReminderMail": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "referenceId": { - "type": "integer" - }, - "reminderType": { - "type": "string", - "enum": ["PENDING_BOOKING_CONFIRMATION"] - }, - "elapsedMinutes": { - "type": "integer" - }, - "createdAt": { - "type": "string", - "format": "date-time" - } - } - }, - "Payment": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "uid": { - "type": "string" - }, - "type": { - "type": "string", - "enum": ["STRIPE"] - }, - "booking": { - "anyOf": [ - { - "$ref": "#/components/schemas/Booking" - }, - { - "type": "null" - } - ] - }, - "amount": { - "type": "integer" - }, - "fee": { - "type": "integer" - }, - "currency": { - "type": "string" - }, - "success": { - "type": "boolean" - }, - "refunded": { - "type": "boolean" - }, - "data": { - "type": ["number", "string", "boolean", "object", "array", "null"] - }, - "externalId": { - "type": "string" - } - } - }, - "Webhook": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "subscriberUrl": { - "type": "string" - }, - "payloadTemplate": { - "type": ["string", "null"] - }, - "createdAt": { - "type": "string", - "format": "date-time" - }, - "active": { - "type": "boolean", - "default": true - }, - "eventTriggers": { - "type": "array", - "enum": ["BOOKING_CREATED", "BOOKING_RESCHEDULED", "BOOKING_CANCELLED"] - }, - "user": { - "anyOf": [ - { - "$ref": "#/components/schemas/User" - }, - { - "type": "null" - } - ] - }, - "eventType": { - "anyOf": [ - { - "$ref": "#/components/schemas/EventType" - }, - { - "type": "null" - } - ] - } - } - }, - "ApiKey": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "user": { - "anyOf": [ - { - "$ref": "#/components/schemas/User" - }, - { - "type": "null" - } - ] - }, - "createdAt": { - "type": "string", - "format": "date-time" - }, - "expiresAt": { - "type": "string", - "format": "date-time" - }, - "note": { - "type": ["string", "null"] - } - } - } - }, - "type": "object", - "properties": { - "eventType": { - "$ref": "#/components/schemas/EventType" - }, - "credential": { - "$ref": "#/components/schemas/Credential" - }, - "destinationCalendar": { - "$ref": "#/components/schemas/DestinationCalendar" - }, - "user": { - "$ref": "#/components/schemas/User" - }, - "team": { - "$ref": "#/components/schemas/Team" - }, - "membership": { - "$ref": "#/components/schemas/Membership" - }, - "verificationRequest": { - "$ref": "#/components/schemas/VerificationRequest" - }, - "bookingReference": { - "$ref": "#/components/schemas/BookingReference" - }, - "attendee": { - "$ref": "#/components/schemas/Attendee" - }, - "dailyEventReference": { - "$ref": "#/components/schemas/DailyEventReference" - }, - "booking": { - "$ref": "#/components/schemas/Booking" - }, - "schedule": { - "$ref": "#/components/schemas/Schedule" - }, - "availability": { - "$ref": "#/components/schemas/Availability" - }, - "selectedCalendar": { - "$ref": "#/components/schemas/SelectedCalendar" - }, - "eventTypeCustomInput": { - "$ref": "#/components/schemas/EventTypeCustomInput" - }, - "resetPasswordRequest": { - "$ref": "#/components/schemas/ResetPasswordRequest" - }, - "reminderMail": { - "$ref": "#/components/schemas/ReminderMail" - }, - "payment": { - "$ref": "#/components/schemas/Payment" - }, - "webhook": { - "$ref": "#/components/schemas/Webhook" - }, - "apiKey": { - "$ref": "#/components/schemas/ApiKey" - } - } -} diff --git a/next.config.js b/next.config.js index fa5bc84e10..1542c7f0ff 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,3 @@ -// https://www.npmjs.com/package/next-transpile-modules -// This makes our @calcom/prisma package from the monorepo to be transpiled and usable by API const withTM = require("next-transpile-modules")([ "@calcom/app-store", "@calcom/prisma", @@ -7,13 +5,11 @@ const withTM = require("next-transpile-modules")([ "@calcom/ee", ]); -// use something like withPlugins([withTM], {}) if more plugins added later. - module.exports = withTM({ async headers() { return [ { - // matching all API routes + // @note: disabling CORS matching all API routes as this will be a our Public API source: "/api/:path*", headers: [ { key: "Access-Control-Allow-Credentials", value: "true" }, @@ -30,12 +26,12 @@ module.exports = withTM({ }, async rewrites() { return [ - // This redirects requests recieved at / the root to the /api/ folder. + // @note: redirects requests from: "/:rest*" the root level to the "/api/:rest*" folder by default. { source: "/:rest*", destination: "/api/:rest*", }, - // This redirects requests to api/v*/ to /api/ passing version as a query parameter. + // @note: redirects requests from api/v*/:rest to /api/:rest?version=* passing version as a query parameter. { source: "/api/v:version/:rest*", destination: "/api/:rest*?version=:version", From 005d0f804046be8b40658ebc4fad4a98d0b39ab5 Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Sat, 30 Apr 2022 19:46:04 +0200 Subject: [PATCH 09/11] fix: channels removed --- package.json | 1 + pages/api/docs.ts | 16 ++++++++++++++-- pages/api/users/[id].ts | 3 +++ pages/api/users/index.ts | 3 ++- types.d.ts | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 types.d.ts diff --git a/package.json b/package.json index 0c1cb9556e..42f655236a 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "@calcom/prisma": "*", "@sentry/nextjs": "^6.19.3", + "modify-response-middleware": "^1.1.0", "next": "^12.1.4", "next-api-middleware": "^1.0.1", "next-swagger-doc": "^0.2.1", diff --git a/pages/api/docs.ts b/pages/api/docs.ts index e87c6c1f5c..1e8bcf2175 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -1,6 +1,9 @@ -import jsonSchema from "@/json-schema/json-schema.json"; import pjson from "@/package.json"; +// import cors from "cors"; +import modifyRes from "modify-response-middleware"; +import { use } from "next-api-middleware"; import { withSwagger } from "next-swagger-doc"; +import { NextApiRequest, NextApiResponse } from "next/types"; const swaggerHandler = withSwagger({ definition: { @@ -25,4 +28,13 @@ const swaggerHandler = withSwagger({ }, apiFolder: "pages/api", }); -export default swaggerHandler(); + +export default use( + modifyRes((content: string, _req: NextApiRequest, _res: NextApiResponse) => { + if (content) { + const parsed = JSON.parse(content); + delete parsed.channels; + return Buffer.from(JSON.stringify(parsed)); + } + }) +)(swaggerHandler()); diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts index 58d0b41d36..6b3e7ec784 100644 --- a/pages/api/users/[id].ts +++ b/pages/api/users/[id].ts @@ -15,6 +15,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * /users/{id}: * get: * summary: Find a user, returns your user if regular user. + * operationId: getUserById * parameters: * - in: path * name: id @@ -33,6 +34,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * description: User was not found * patch: * summary: Edit an existing user + * operationId: editUserById * parameters: * - in: path * name: id @@ -51,6 +53,7 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations * description: Authorization information is missing or invalid. * delete: * summary: Remove an existing user + * operationId: deleteUserById * parameters: * - in: path * name: id diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index 4ef860e18f..5f6c64d604 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -10,9 +10,10 @@ import { schemaUserReadPublic } from "@lib/validations/user"; * @swagger * /users: * get: - * summary: Find all users (admin only), returns your user if regular user. + * summary: Find all users. * tags: * - users + * operationId: listUsers * responses: * 200: * description: OK diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 0000000000..9a7af651d1 --- /dev/null +++ b/types.d.ts @@ -0,0 +1 @@ +declare module "modify-response-middleware"; From e27600b8c7c5f5eddd943b29ee13d56114f6f43c Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Sat, 30 Apr 2022 19:47:26 +0200 Subject: [PATCH 10/11] remove comment --- pages/api/docs.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/pages/api/docs.ts b/pages/api/docs.ts index 1e8bcf2175..dd544e89ae 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -1,5 +1,4 @@ import pjson from "@/package.json"; -// import cors from "cors"; import modifyRes from "modify-response-middleware"; import { use } from "next-api-middleware"; import { withSwagger } from "next-swagger-doc"; From b572e4b0ffb5a6c8d4f0c0a9a463c5a3e53aa43d Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Sat, 30 Apr 2022 20:53:19 +0200 Subject: [PATCH 11/11] fix: move all req to deconstructed --- README.md | 2 - lib/helpers/verifyApiKey.ts | 18 ++--- pages/api/availabilities/index.ts | 4 +- pages/api/booking-references/[id].ts | 93 +++++++++++++------------ pages/api/booking-references/index.ts | 1 + pages/api/bookings/index.ts | 4 +- pages/api/payments/index.ts | 4 +- pages/api/schedules/[id].ts | 7 +- pages/api/schedules/index.ts | 7 +- pages/api/selected-calendars/[id].ts | 4 +- pages/api/selected-calendars/index.ts | 4 +- pages/api/teams/[id].ts | 7 +- pages/api/teams/index.ts | 65 +++++++++-------- pages/api/users/[id].ts | 3 +- pages/api/users/index.ts | 3 +- templates/endpoints/[id]/delete.ts | 6 +- templates/endpoints/[id]/edit.ts | 6 +- templates/endpoints/[id]/index.ts | 4 +- templates/endpoints/get_all_and_post.ts | 39 ++++++----- templates/endpoints/post.ts | 6 +- types.d.ts | 1 + 21 files changed, 148 insertions(+), 140 deletions(-) diff --git a/README.md b/README.md index a9904ac3ff..4bba94e69a 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,6 @@ We have some shared validations which several resources require, like baseApiPar - **[*]BodyParams** which merges both `[*]BaseBodyParams.merge([*]RequiredParams);` -- **withValid[*]** which is currently not being much used because is only useful in only post endpoints (we do post/get all in same file). This would validate the req.body of a POST call to API against our BaseBodyParams validation - ### Next Validations [Next-Validations Docs](https://next-validations.productsway.com/) diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index cf5c4a8472..c4fabac652 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -8,6 +8,8 @@ import prisma from "@calcom/prisma"; declare module "next" { export interface NextApiRequest extends IncomingMessage { userId: number; + body: any; + query: { [key: string]: string | string[] }; } } @@ -20,21 +22,21 @@ export const dateNotInPast = function (date: Date) { }; // This verifies the apiKey and sets the user if it is valid. -export const verifyApiKey: NextMiddleware = async (req, res, next) => { - if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" }); +export const verifyApiKey: NextMiddleware = async ({ query: { apiKey }, ...req }, res, next) => { + if (!apiKey) return res.status(401).json({ message: "No apiKey provided" }); // We remove the prefix from the user provided api_key. If no env set default to "cal_" - const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", ""); + const strippedApiKey = `${apiKey}`.replace(process.env.API_KEY_PREFIX || " cal_", ""); // Hash the key again before matching against the database records. const hashedKey = hashAPIKey(strippedApiKey); // Check if the hashed api key exists in database. - const apiKey = await prisma.apiKey.findUnique({ where: { hashedKey } }); + const validApiKey = await prisma.apiKey.findUnique({ where: { hashedKey } }); // If we cannot find any api key. Throw a 401 Unauthorized. - if (!apiKey) return res.status(401).json({ error: "Your apiKey is not valid" }); - if (apiKey.expiresAt && dateNotInPast(apiKey.expiresAt)) { + if (!validApiKey) return res.status(401).json({ error: "Your apiKey is not valid" }); + if (validApiKey.expiresAt && dateNotInPast(validApiKey.expiresAt)) { return res.status(401).json({ error: "This apiKey is expired" }); } - if (!apiKey.userId) return res.status(404).json({ error: "No user found for this apiKey" }); + if (!validApiKey.userId) return res.status(404).json({ error: "No user found for this apiKey" }); /* We save the user id in the request for later use */ - req.userId = apiKey.userId; + req.userId = validApiKey.userId; await next(); }; diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts index 25b0866071..c7b53c211d 100644 --- a/pages/api/availabilities/index.ts +++ b/pages/api/availabilities/index.ts @@ -10,7 +10,7 @@ import { } from "@lib/validations/availability"; async function createOrlistAllAvailabilities( - { method, userId }: NextApiRequest, + { method, body, userId }: NextApiRequest, res: NextApiResponse ) { if (method === "GET") { @@ -58,7 +58,7 @@ async function createOrlistAllAvailabilities( * 401: * description: Authorization information is missing or invalid. */ - const safe = schemaAvailabilityCreateBodyParams.safeParse(req.body); + const safe = schemaAvailabilityCreateBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.availability.create({ data: { ...safe.data, userId } }); diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index cb0358d901..03bc87fafb 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -27,32 +27,33 @@ export async function bookingReferenceById( if (!userWithBookings) throw new Error("User not found"); const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); const bookingReference = await prisma.bookingReference.findUnique({ where: { id: safeQuery.data.id } }); - if (!bookingReference) throw new Error("BookingReference not found"); + if (!bookingReference?.bookingId) throw new Error("BookingReference: bookingId not found"); if (userBookingIds.includes(bookingReference.bookingId)) { switch (method) { - /** - * @swagger - * /booking-references/{id}: - * get: - * summary: Find a booking reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking reference to get - * tags: - * - booking-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: BookingReference was not found - */ case "GET": + /** + * @swagger + * /booking-references/{id}: + * get: + * summary: Find a booking reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking reference to get + * tags: + * - booking-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: BookingReference was not found + */ + await prisma.bookingReference .findUnique({ where: { id: safeQuery.data.id } }) .then((data) => schemaBookingReferenceReadPublic.parse(data)) @@ -63,30 +64,32 @@ export async function bookingReferenceById( error, }) ); + break; - /** - * @swagger - * /booking-references/{id}: - * patch: - * summary: Edit an existing booking reference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking reference to edit - * tags: - * - booking-references - * responses: - * 201: - * description: OK, bookingReference edited successfuly - * 400: - * description: Bad request. BookingReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ case "PATCH": + /** + * @swagger + * /booking-references/{id}: + * patch: + * summary: Edit an existing booking reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking reference to edit + * tags: + * - booking-references + * responses: + * 201: + * description: OK, bookingReference edited successfuly + * 400: + * description: Bad request. BookingReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ + const safeBody = schemaBookingEditBodyParams.safeParse(body); if (!safeBody.success) { throw new Error("Invalid request body"); diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts index 87cbe25cdc..c228673240 100644 --- a/pages/api/booking-references/index.ts +++ b/pages/api/booking-references/index.ts @@ -75,6 +75,7 @@ async function createOrlistAllBookingReferences( throw new Error("User not found"); } const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat(); + if (!safe.data.bookingId) throw new Error("BookingReference: bookingId not found"); if (!userBookingIds.includes(safe.data.bookingId)) res.status(401).json({ message: "Unauthorized" }); else { const booking_reference = await prisma.bookingReference.create({ diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 57a774a916..bd1595ff6c 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -7,7 +7,7 @@ import { BookingResponse, BookingsResponse } from "@lib/types"; import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking"; async function createOrlistAllBookings( - { method, userId }: NextApiRequest, + { method, body, userId }: NextApiRequest, res: NextApiResponse ) { if (method === "GET") { @@ -51,7 +51,7 @@ async function createOrlistAllBookings( * 401: * description: Authorization information is missing or invalid. */ - const safe = schemaBookingCreateBodyParams.safeParse(req.body); + const safe = schemaBookingCreateBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.booking.create({ data: { ...safe.data, userId } }); diff --git a/pages/api/payments/index.ts b/pages/api/payments/index.ts index 0c6eae0f85..d758421f46 100644 --- a/pages/api/payments/index.ts +++ b/pages/api/payments/index.ts @@ -21,9 +21,7 @@ import { schemaPaymentPublic } from "@lib/validations/payment"; * 404: * description: No payments were found */ -async function allPayments(req: NextApiRequest, res: NextApiResponse) { - const userId = req.userId; - +async function allPayments({ userId }: NextApiRequest, res: NextApiResponse) { const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts index af63d8af2b..38066c4ab8 100644 --- a/pages/api/schedules/[id].ts +++ b/pages/api/schedules/[id].ts @@ -10,12 +10,13 @@ import { withValidQueryIdTransformParseInt, } from "@lib/validations/shared/queryIdTransformParseInt"; -export async function scheduleById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +export async function scheduleById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaScheduleBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const userSchedules = await prisma.schedule.findMany({ where: { userId } }); const userScheduleIds = userSchedules.map((schedule) => schedule.id); if (!userScheduleIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" }); diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts index 5da47e226c..04dbc6b1a1 100644 --- a/pages/api/schedules/index.ts +++ b/pages/api/schedules/index.ts @@ -7,12 +7,9 @@ import { ScheduleResponse, SchedulesResponse } from "@lib/types"; import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule"; async function createOrlistAllSchedules( - req: NextApiRequest, + { method, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method } = req; - const userId = req.userId; - if (method === "GET") { /** * @swagger @@ -54,7 +51,7 @@ async function createOrlistAllSchedules( * 401: * description: Authorization information is missing or invalid. */ - const safe = schemaScheduleBodyParams.safeParse(req.body); + const safe = schemaScheduleBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const data = await prisma.schedule.create({ data: { ...safe.data, userId } }); const schedule = schemaSchedulePublic.parse(data); diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts index 10fb737cf9..de4d7a5570 100644 --- a/pages/api/selected-calendars/[id].ts +++ b/pages/api/selected-calendars/[id].ts @@ -11,16 +11,14 @@ import { import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; export async function selectedCalendarById( - req: NextApiRequest, + { method, query, body, userId }: NextApiRequest, res: NextApiResponse ) { - const { method, query, body } = req; const safeQuery = schemaQueryIdAsString.safeParse(query); const safeBody = schemaSelectedCalendarBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); // This is how we set the userId and externalId in the query for managing compoundId. const [paramUserId, integration, externalId] = safeQuery.data.id.split("_"); - const userId = req.userId; if (userId !== parseInt(paramUserId)) res.status(401).json({ message: "Unauthorized" }); else { switch (method) { diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts index 758d663b8f..cbf2e94b81 100644 --- a/pages/api/selected-calendars/index.ts +++ b/pages/api/selected-calendars/index.ts @@ -10,7 +10,7 @@ import { } from "@lib/validations/selected-calendar"; async function createOrlistAllSelectedCalendars( - { method, userId }: NextApiRequest, + { method, body, userId }: NextApiRequest, res: NextApiResponse ) { if (method === "GET") { @@ -67,7 +67,7 @@ async function createOrlistAllSelectedCalendars( * 401: * description: Authorization information is missing or invalid. */ - const safe = schemaSelectedCalendarBodyParams.safeParse(req.body); + const safe = schemaSelectedCalendarBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); // Create new selectedCalendar connecting it to current userId const data = await prisma.selectedCalendar.create({ diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts index d3e971d487..e49277a143 100644 --- a/pages/api/teams/[id].ts +++ b/pages/api/teams/[id].ts @@ -68,12 +68,13 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; * 401: * description: Authorization information is missing or invalid. */ -export async function teamById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; +export async function teamById( + { method, query, body, userId }: NextApiRequest, + res: NextApiResponse +) { const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaTeamBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = req.userId; const userWithMemberships = await prisma.membership.findMany({ where: { userId: userId }, }); diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.ts index e5ae852dd8..75aabd47b9 100644 --- a/pages/api/teams/index.ts +++ b/pages/api/teams/index.ts @@ -7,36 +7,26 @@ import { TeamResponse, TeamsResponse } from "@lib/types"; import { schemaMembershipPublic } from "@lib/validations/membership"; import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; -/** - * @swagger - * /teams: - * get: - * summary: Find all teams - * tags: - * - teams - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No teams were found - * post: - * summary: Creates a new team - * tags: - * - teams - * responses: - * 201: - * description: OK, team created - * 400: - * description: Bad request. Team body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -async function createOrlistAllTeams(req: NextApiRequest, res: NextApiResponse) { - const { method } = req; - const userId = req.userId; +async function createOrlistAllTeams( + { method, body, userId }: NextApiRequest, + res: NextApiResponse +) { if (method === "GET") { + /** + * @swagger + * /teams: + * get: + * summary: Find all teams + * tags: + * - teams + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No teams were found + */ const userWithMemberships = await prisma.membership.findMany({ where: { userId: userId }, }); @@ -50,7 +40,22 @@ async function createOrlistAllTeams(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body, userId } = req; +export async function userById({ method, query, body, userId }: NextApiRequest, res: NextApiResponse) { const safeQuery = schemaQueryIdParseInt.safeParse(query); console.log(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index 5f6c64d604..046d456de9 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -22,8 +22,7 @@ import { schemaUserReadPublic } from "@lib/validations/user"; * 404: * description: No users were found */ -async function allUsers(req: NextApiRequest, res: NextApiResponse) { - const userId = req.userId; +async function allUsers({ userId }: NextApiRequest, res: NextApiResponse) { const data = await prisma.user.findMany({ where: { id: userId, diff --git a/templates/endpoints/[id]/delete.ts b/templates/endpoints/[id]/delete.ts index 908e74b7d5..133554ac25 100644 --- a/templates/endpoints/[id]/delete.ts +++ b/templates/endpoints/[id]/delete.ts @@ -32,9 +32,9 @@ import { * 401: * description: Authorization information is missing or invalid. */ -export async function deleteResource(req: NextApiRequest, res: NextApiResponse) { - const safe = schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); +export async function deleteResource({query}: NextApiRequest, res: NextApiResponse) { + const safe = schemaQueryIdParseInt.safeParse(query); + if (!safe.success) throw new Error("Invalid request query"); const data = await prisma.resource.delete({ where: { id: safe.data.id } }); diff --git a/templates/endpoints/[id]/edit.ts b/templates/endpoints/[id]/edit.ts index 43cb6c8f8e..e72198d82e 100644 --- a/templates/endpoints/[id]/edit.ts +++ b/templates/endpoints/[id]/edit.ts @@ -33,9 +33,9 @@ import { * 401: * description: Authorization information is missing or invalid. */ -export async function editResource(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = schemaQueryIdParseInt.safeParse(req.query); - const safeBody = schemaResourceBodyParams.safeParse(req.body); +export async function editResource({query, body}: NextApiRequest, res: NextApiResponse) { + const safeQuery = schemaQueryIdParseInt.safeParse(query); + const safeBody = schemaResourceBodyParams.safeParse(body); if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); const resource = await prisma.resource.update({ diff --git a/templates/endpoints/[id]/index.ts b/templates/endpoints/[id]/index.ts index c9b1d85152..4a0656d3b5 100644 --- a/templates/endpoints/[id]/index.ts +++ b/templates/endpoints/[id]/index.ts @@ -33,8 +33,8 @@ import { * 404: * description: Resource was not found */ -export async function resourceById(req: NextApiRequest, res: NextApiResponse) { - const safe = schemaQueryIdParseInt.safeParse(req.query); +export async function resourceById({query}: NextApiRequest, res: NextApiResponse) { + const safe = schemaQueryIdParseInt.safeParse(query); if (!safe.success) throw new Error("Invalid request query"); const resource = await prisma.resource.findUnique({ where: { id: safe.data.id } }); diff --git a/templates/endpoints/get_all_and_post.ts b/templates/endpoints/get_all_and_post.ts index d20075e52c..e21dc8bb9d 100644 --- a/templates/endpoints/get_all_and_post.ts +++ b/templates/endpoints/get_all_and_post.ts @@ -6,6 +6,12 @@ import { withMiddleware } from "@lib/helpers/withMiddleware"; import { PaymentResponse, PaymentsResponse } from "@lib/types"; import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/payment"; +async function createOrlistAllPayments( + {method, body}: NextApiRequest, + res: NextApiResponse +) { + if (method === "GET") { + /** * @swagger * /v1/payments: @@ -21,6 +27,21 @@ import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/p * description: Authorization information is missing or invalid. * 404: * description: No payments were found + */ + const payments = await prisma.payment.findMany(); + const data = payments.map((payment) => schemaPaymentPublic.parse(payment)); + if (data) res.status(200).json({ data }); + else + (error: Error) => + res.status(404).json({ + message: "No Payments were found", + error, + }); + } else if (method === "POST") { + +/** + * @swagger + * /v1/payments: * post: * summary: Creates a new payment @@ -34,23 +55,7 @@ import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/p * 401: * description: Authorization information is missing or invalid. */ -async function createOrlistAllPayments( - req: NextApiRequest, - res: NextApiResponse -) { - const { method } = req; - if (method === "GET") { - const payments = await prisma.payment.findMany(); - const data = payments.map((payment) => schemaPaymentPublic.parse(payment)); - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "No Payments were found", - error, - }); - } else if (method === "POST") { - const safe = schemaPaymentBodyParams.safeParse(req.body); + const safe = schemaPaymentBodyParams.safeParse(body); if (!safe.success) throw new Error("Invalid request body"); const payment = await prisma.payment.create({ data: safe.data }); diff --git a/templates/endpoints/post.ts b/templates/endpoints/post.ts index 3f5b7403d7..896c09e691 100644 --- a/templates/endpoints/post.ts +++ b/templates/endpoints/post.ts @@ -29,9 +29,9 @@ import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } fro * 401: * description: Authorization information is missing or invalid. */ -async function createResource(req: NextApiRequest, res: NextApiResponse) { - const safe = schemaResourceBodyParams.safeParse(req.body); - if (!safe.success) throw new Error("Invalid request body", safe.error); +async function createResource({body}: NextApiRequest, res: NextApiResponse) { + const safe = schemaResourceBodyParams.safeParse(body); + if (!safe.success) throw new Error("Invalid request body"); const resource = await prisma.resource.create({ data: safe.data }); const data = schemaResourcePublic.parse(resource); diff --git a/types.d.ts b/types.d.ts index 9a7af651d1..2abf07e4c1 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1 +1,2 @@ declare module "modify-response-middleware"; +