first commit

This commit is contained in:
eric committed 2022-11-09 21:28:20 +01:00
commit 6857e301fa
23 files changed
+5500

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react';
import prisma from '../../../lib/prisma'
// DELETE /api/post/:id
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
const postId = req.query.id;
const session = await getSession({ req })
if (req.method === "DELETE") {
if (session) {
const post = await prisma.post.delete({
where: { id: Number(postId) },
});
res.json(post);
} else {
res.status(401).send({ message: 'Unauthorized' })
}
} else {
throw new Error(
`The HTTP ${req.method} method is not supported at this route.`
);
}
}