backup page done
This commit is contained in:
34
apps/Backend/src/routes/notifications.ts
Normal file
34
apps/Backend/src/routes/notifications.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { prisma } from "@repo/db/client";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
const userId = (req as any).user?.id;
|
||||
const notifications = await prisma.notification.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 20,
|
||||
});
|
||||
res.json(notifications);
|
||||
});
|
||||
|
||||
router.post("/:id/read", async (req, res) => {
|
||||
const userId = (req as any).user?.id;
|
||||
await prisma.notification.updateMany({
|
||||
where: { id: Number(req.params.id), userId },
|
||||
data: { read: true },
|
||||
});
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
router.post("/read-all", async (req, res) => {
|
||||
const userId = (req as any).user?.id;
|
||||
await prisma.notification.updateMany({
|
||||
where: { userId },
|
||||
data: { read: true },
|
||||
});
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user