2022-03-28 22:27:14 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
|
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
|
|
|
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
2022-03-29 01:59:57 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
type ResponseData = {
|
|
|
|
message?: string;
|
|
|
|
error?: unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
2022-03-29 01:59:57 +00:00
|
|
|
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
|
|
|
if (safe.success) {
|
|
|
|
const deletedDailyEventReference = await prisma.dailyEventReference
|
2022-03-28 22:27:14 +00:00
|
|
|
.delete({ where: { id: safe.data.id } })
|
|
|
|
// We only remove the dailyEventReference type from the database if there's an existing resource.
|
2022-03-29 01:59:57 +00:00
|
|
|
if (deletedDailyEventReference) res.status(200).json({ message: `dailyEventReference with id: ${safe.data.id} deleted successfully` });
|
2022-03-28 22:27:14 +00:00
|
|
|
// This catches the error thrown by prisma.dailyEventReference.delete() if the resource is not found.
|
|
|
|
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
|
|
|
// Reject any other HTTP method than POST
|
|
|
|
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:59:57 +00:00
|
|
|
// export default withValidQueryIdTransformParseInt(deleteDailyEventReference);
|
|
|
|
export default withMiddleware("deleteOnly")(
|
|
|
|
withValidQueryIdTransformParseInt(
|
|
|
|
deleteDailyEventReference
|
|
|
|
)
|
|
|
|
);
|