2021-08-19 12:27:01 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import prisma from "../../../../lib/prisma";
|
2021-09-03 20:51:21 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-06-05 22:53:33 +00:00
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
2021-08-19 12:27:01 +00:00
|
|
|
const session = await getSession({ req: req });
|
2021-06-05 22:53:33 +00:00
|
|
|
if (!session) {
|
2021-08-19 12:27:01 +00:00
|
|
|
return res.status(401).json({ message: "Not authenticated" });
|
2021-06-05 22:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DELETE /api/teams/{team}
|
|
|
|
if (req.method === "DELETE") {
|
2021-08-19 12:27:01 +00:00
|
|
|
await prisma.membership.delete({
|
2021-06-05 22:53:33 +00:00
|
|
|
where: {
|
2021-08-19 12:27:01 +00:00
|
|
|
userId_teamId: { userId: session.user.id, teamId: parseInt(req.query.team) },
|
|
|
|
},
|
2021-06-05 22:53:33 +00:00
|
|
|
});
|
2021-08-19 12:27:01 +00:00
|
|
|
await prisma.team.delete({
|
2021-06-05 22:53:33 +00:00
|
|
|
where: {
|
|
|
|
id: parseInt(req.query.team),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return res.status(204).send(null);
|
|
|
|
}
|
2021-08-19 12:27:01 +00:00
|
|
|
}
|