32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
|
import {
|
|
schemaQueryIdParseInt,
|
|
withValidQueryIdTransformParseInt,
|
|
} from "@lib/validations/shared/queryIdTransformParseInt";
|
|
|
|
type ResponseData = {
|
|
message: string;
|
|
error?: object;
|
|
};
|
|
|
|
export async function deleteTeam(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
|
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
|
if (!safe.success) throw new Error("Invalid request query");
|
|
|
|
const data = await prisma.team.delete({ where: { id: safe.data.id } });
|
|
|
|
if (data) res.status(200).json({ message: `Team with id: ${safe.data.id} deleted successfully` });
|
|
else
|
|
(error: Error) =>
|
|
res.status(400).json({
|
|
message: `Team with id: ${safe.data.id} was not able to be processed`,
|
|
error,
|
|
});
|
|
}
|
|
|
|
export default withMiddleware("HTTP_DELETE", "addRequestId")(withValidQueryIdTransformParseInt(deleteTeam));
|