From 9c5624c748f82e5e4a4d67e64a7732ebd647b3bc Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Thu, 21 Apr 2022 00:50:34 +0200 Subject: [PATCH] fix: delete reminder mails endpoints for now as no userId, consult if needed --- pages/api/reminder-mails/[id].ts | 136 ------------------------------ pages/api/reminder-mails/index.ts | 76 ----------------- 2 files changed, 212 deletions(-) delete mode 100644 pages/api/reminder-mails/[id].ts delete mode 100644 pages/api/reminder-mails/index.ts diff --git a/pages/api/reminder-mails/[id].ts b/pages/api/reminder-mails/[id].ts deleted file mode 100644 index e6627ef7b9..0000000000 --- a/pages/api/reminder-mails/[id].ts +++ /dev/null @@ -1,136 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { ReminderMailResponse } from "@lib/types"; -import { schemaReminderMailBodyParams, schemaReminderMailPublic } from "@lib/validations/reminder-mail"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /v1/reminder-mails/{id}: - * get: - * summary: Get a reminderMail by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the reminderMail to get - * security: - * - ApiKeyAuth: [] - * tags: - * - reminder-mails - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: ReminderMail was not found - * patch: - * summary: Edit an existing reminderMail - * consumes: - * - application/json - * parameters: - * - in: body - * name: reminderMail - * description: The reminderMail to edit - * schema: - * type: object - * $ref: '#/components/schemas/ReminderMail' - * required: true - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the reminderMail to edit - * security: - * - ApiKeyAuth: [] - * tags: - * - reminder-mails - * responses: - * 201: - * description: OK, reminderMail edited successfuly - * model: ReminderMail - * 400: - * description: Bad request. ReminderMail body is invalid. - * 401: - * description: Authorization information is missing or invalid. - * delete: - * summary: Remove an existing reminderMail - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the reminderMail to delete - * security: - * - ApiKeyAuth: [] - * tags: - * - reminder-mails - * responses: - * 201: - * description: OK, reminderMail removed successfuly - * model: ReminderMail - * 400: - * description: Bad request. ReminderMail id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function reminderMailById(req: NextApiRequest, res: NextApiResponse) { - const { method, query, body } = req; - const safeQuery = schemaQueryIdParseInt.safeParse(query); - const safeBody = schemaReminderMailBodyParams.safeParse(body); - if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - - switch (method) { - case "GET": - await prisma.reminderMail - .findUnique({ where: { id: safeQuery.data.id } }) - .then((data) => schemaReminderMailPublic.parse(data)) - .then((reminder_mail) => res.status(200).json({ reminder_mail })) - .catch((error: Error) => - res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }) - ); - break; - - case "PATCH": - if (!safeBody.success) throw new Error("Invalid request body"); - await prisma.reminderMail - .update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }) - .then((reminderMail) => schemaReminderMailPublic.parse(reminderMail)) - .then((reminder_mail) => res.status(200).json({ reminder_mail })) - .catch((error: Error) => - res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }) - ); - break; - - case "DELETE": - await prisma.reminderMail - .delete({ where: { id: safeQuery.data.id } }) - .then(() => - res.status(200).json({ message: `ReminderMail with id: ${safeQuery.data.id} deleted successfully` }) - ) - .catch((error: Error) => - res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }) - ); - break; - - default: - res.status(405).json({ message: "Method not allowed" }); - break; - } -} - -export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(reminderMailById)); diff --git a/pages/api/reminder-mails/index.ts b/pages/api/reminder-mails/index.ts deleted file mode 100644 index 22c4f63dab..0000000000 --- a/pages/api/reminder-mails/index.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { ReminderMailResponse, ReminderMailsResponse } from "@lib/types"; -import { - schemaReminderMailBodyParams, - schemaReminderMailPublic, - withValidReminderMail, -} from "@lib/validations/reminder-mail"; - -/** - * @swagger - * /v1/reminder-mails: - * get: - * summary: Get all reminder mails - * security: - * - ApiKeyAuth: [] - * tags: - * - reminder-mails - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No reminder mails were found - * post: - * summary: Creates a new reminder mail - * security: - * - ApiKeyAuth: [] - * tags: - * - reminder-mails - * responses: - * 201: - * description: OK, reminder mail created - * model: ReminderMail - * 400: - * description: Bad request. ReminderMail body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -async function createOrlistAllReminderMails( - req: NextApiRequest, - res: NextApiResponse -) { - const { method } = req; - if (method === "GET") { - const data = await prisma.reminderMail.findMany(); - const reminder_mails = data.map((reminderMail) => schemaReminderMailPublic.parse(reminderMail)); - if (reminder_mails) res.status(200).json({ reminder_mails }); - else - (error: Error) => - res.status(404).json({ - message: "No ReminderMails were found", - error, - }); - } else if (method === "POST") { - const safe = schemaReminderMailBodyParams.safeParse(req.body); - if (!safe.success) throw new Error("Invalid request body"); - - const data = await prisma.reminderMail.create({ data: safe.data }); - const reminder_mail = schemaReminderMailPublic.parse(data); - - if (reminder_mail) res.status(201).json({ reminder_mail, message: "reminder mail created successfully" }); - else - (error: Error) => - res.status(400).json({ - message: "could not create new reminder mail", - error, - }); - } else res.status(405).json({ message: `Method ${method} not allowed` }); -} - -export default withMiddleware("HTTP_GET_OR_POST")(withValidReminderMail(createOrlistAllReminderMails));