fix: delete reminder mails endpoints for now as no userId, consult if needed

pull/9078/head
Agusti Fernandez Pardo 2022-04-21 00:50:34 +02:00
parent cabe4ae9c6
commit 9c5624c748
2 changed files with 0 additions and 212 deletions

View File

@ -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<ReminderMailResponse>) {
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));

View File

@ -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<ReminderMailsResponse | ReminderMailResponse>
) {
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));