Skip to content

Scheduling infrastructure for absolutely everyone.

Swagger/schedules request and response examples (#257)

Syed Ali Shahbaz38987b77bb82
diff --git a/pages/api/schedules/[id]/_get.ts b/pages/api/schedules/[id]/_get.ts
index 27502833fd7..fdadce2cba8 100644
--- a/pages/api/schedules/[id]/_get.ts
+++ b/pages/api/schedules/[id]/_get.ts
@@ -29,11 +29,48 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* responses:
* 200:
* description: OK
+ * content:
+ * application/json:
+ * examples:
+ * schedule:
+ * value:
+ * {
+ * "schedule": {
+ * "id": 12345,
+ * "userId": 182,
+ * "name": "Sample Schedule",
+ * "timeZone": "Asia/Calcutta",
+ * "availability": [
+ * {
+ * "id": 111,
+ * "eventTypeId": null,
+ * "days": [0, 1, 2, 3, 4, 6],
+ * "startTime": "00:00:00",
+ * "endTime": "23:45:00"
+ * },
+ * {
+ * "id": 112,
+ * "eventTypeId": null,
+ * "days": [5],
+ * "startTime": "00:00:00",
+ * "endTime": "12:00:00"
+ * },
+ * {
+ * "id": 113,
+ * "eventTypeId": null,
+ * "days": [5],
+ * "startTime": "15:00:00",
+ * "endTime": "23:45:00"
+ * }
+ * ]
+ * }
+ * }
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: Schedule was not found
*/
+
export async function getHandler(req: NextApiRequest) {
const { prisma, query } = req;
const { id } = schemaQueryIdParseInt.parse(query);
diff --git a/pages/api/schedules/[id]/_patch.ts b/pages/api/schedules/[id]/_patch.ts
index 85c67e91c03..1c8f52d688e 100644
--- a/pages/api/schedules/[id]/_patch.ts
+++ b/pages/api/schedules/[id]/_patch.ts
@@ -27,7 +27,7 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* required: true
* description: Your API Key
* requestBody:
- * description: Create a new schedule
+ * description: Edit an existing schedule
* required: true
* content:
* application/json:
@@ -37,19 +37,49 @@ import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransform
* name:
* type: string
* description: Name of the schedule
- * timezone:
+ * timeZone:
* type: string
* description: The timezone for this schedule
+ * examples:
+ * schedule:
+ * value:
+ * {
+ * "name": "Updated Schedule",
+ * "timeZone": "Asia/Calcutta"
+ * }
* tags:
* - schedules
* responses:
- * 201:
+ * 200:
* description: OK, schedule edited successfully
+ * content:
+ * application/json:
+ * examples:
+ * schedule:
+ * value:
+ * {
+ * "schedule": {
+ * "id": 12345,
+ * "userId": 1,
+ * "name": "Total Testing Part 2",
+ * "timeZone": "Asia/Calcutta",
+ * "availability": [
+ * {
+ * "id": 4567,
+ * "eventTypeId": null,
+ * "days": [1, 2, 3, 4, 5],
+ * "startTime": "09:00:00",
+ * "endTime": "17:00:00"
+ * }
+ * ]
+ * }
+ * }
* 400:
* description: Bad request. Schedule body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
+
export async function patchHandler(req: NextApiRequest) {
const { prisma, query } = req;
const { id } = schemaQueryIdParseInt.parse(query);
diff --git a/pages/api/schedules/_get.ts b/pages/api/schedules/_get.ts
index 47907808358..1b06a116e9a 100644
--- a/pages/api/schedules/_get.ts
+++ b/pages/api/schedules/_get.ts
@@ -30,11 +30,51 @@ export const schemaUserIds = z
* responses:
* 200:
* description: OK
+ * content:
+ * application/json:
+ * examples:
+ * schedules:
+ * value:
+ * {
+ * "schedules": [
+ * {
+ * "id": 1234,
+ * "userId": 5678,
+ * "name": "Sample Schedule 1",
+ * "timeZone": "America/Chicago",
+ * "availability": [
+ * {
+ * "id": 987,
+ * "eventTypeId": null,
+ * "days": [1, 2, 3, 4, 5],
+ * "startTime": "09:00:00",
+ * "endTime": "23:00:00"
+ * }
+ * ]
+ * },
+ * {
+ * "id": 2345,
+ * "userId": 6789,
+ * "name": "Sample Schedule 2",
+ * "timeZone": "Europe/Amsterdam",
+ * "availability": [
+ * {
+ * "id": 876,
+ * "eventTypeId": null,
+ * "days": [1, 2, 3, 4, 5],
+ * "startTime": "09:00:00",
+ * "endTime": "17:00:00"
+ * }
+ * ]
+ * }
+ * ]
+ * }
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No schedules were found
*/
+
async function handler(req: NextApiRequest) {
const { prisma, userId, isAdmin } = req;
const args: Prisma.ScheduleFindManyArgs = isAdmin ? {} : { where: { userId } };
diff --git a/pages/api/schedules/_post.ts b/pages/api/schedules/_post.ts
index 03c1fb0b6e2..a50f2cd5b61 100644
--- a/pages/api/schedules/_post.ts
+++ b/pages/api/schedules/_post.ts
@@ -29,24 +29,55 @@ import { schemaCreateScheduleBodyParams, schemaSchedulePublic } from "~/lib/vali
* type: object
* required:
* - name
- * - timezone
+ * - timeZone
* properties:
* name:
* type: string
* description: Name of the schedule
- * timezone:
+ * timeZone:
* type: string
- * description: The timezone for this schedule
+ * description: The timeZone for this schedule
+ * examples:
+ * schedule:
+ * value:
+ * {
+ * "name": "Sample Schedule",
+ * "timeZone": "Asia/Calcutta"
+ * }
* tags:
* - schedules
* responses:
- * 201:
+ * 200:
* description: OK, schedule created
+ * content:
+ * application/json:
+ * examples:
+ * schedule:
+ * value:
+ * {
+ * "schedule": {
+ * "id": 79471,
+ * "userId": 182,
+ * "name": "Total Testing",
+ * "timeZone": "Asia/Calcutta",
+ * "availability": [
+ * {
+ * "id": 337917,
+ * "eventTypeId": null,
+ * "days": [1, 2, 3, 4, 5],
+ * "startTime": "09:00:00",
+ * "endTime": "17:00:00"
+ * }
+ * ]
+ * },
+ * "message": "Schedule created successfully"
+ * }
* 400:
* description: Bad request. Schedule body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
+
async function postHandler(req: NextApiRequest) {
const { userId, isAdmin, prisma } = req;
const body = schemaCreateScheduleBodyParams.parse(req.body);