You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
The_Tip_Top/pages/api/publish/[id].ts

20 lines
560 B

import type { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react';
import prisma from '../../../lib/prisma'
// PUT /api/publish/:id
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
const postId = req.query.id;
const session = await getSession({ req })
if (session) {
const post = await prisma.post.update({
where: { id: Number(postId) },
data: { published: true },
});
res.json(post);
} else {
res.status(401).send({ message: 'Unauthorized' })
}
}