import express, { Request, Response } from "express";
import { PrismaClient } from "@prisma/client";
const router = express.Router();
const prisma = new PrismaClient();
router.get("/", async (_req: Request, res: Response) => {
const readPost = await prisma.books.findMany();
res.json(readPost);
});
router.post("/", async (req: Request, res: Response) => {
const data = { data: req.body };
const createPost = await prisma.books.create(data);
res.json(createPost);
});
router.put("/", async (req: Request, res: Response) => {
const updatePost = await prisma.books.update({
where: { id: req.body.id },
data: req.body,
});
res.json(updatePost);
});
router.delete("/", async (req: Request, res: Response) => {
const deletePost = await prisma.books.delete({ where: { id: req.body.id } });
res.json(deletePost);
});
module.exports = router;