Fix notifikasi

Deskripsi:
- Ganti get notifikasi dengan API
This commit is contained in:
2024-12-17 22:40:38 +08:00
parent 3bd2f53732
commit 2fa3f22f9c
13 changed files with 208 additions and 89 deletions

View File

@@ -0,0 +1,63 @@
import { prisma } from "@/app/lib";
import { newFunGetUserId } from "@/app/lib/new_fun_user_id";
import { ICategoryapp } from "@/app_modules/notifikasi/model/interface";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
if (request.method === "GET") {
try {
const { searchParams } = new URL(request.url);
const category = searchParams.get("category") as ICategoryapp;
const page = searchParams.get("page");
const userLoginId = await newFunGetUserId();
const fixPage = _.toNumber(page);
const takeData = 10;
const skipData = fixPage * takeData - takeData;
if (category === "Semua") {
const data = await prisma.notifikasi.findMany({
take: takeData,
skip: skipData,
orderBy: [
{
isRead: "asc",
},
{ createdAt: "desc" },
],
where: {
userId: userLoginId,
userRoleId: "1",
},
});
return NextResponse.json({ success: true, data });
}
const allData = await prisma.notifikasi.findMany({
take: takeData,
skip: skipData,
orderBy: [
{
isRead: "asc",
},
{ createdAt: "desc" },
],
where: {
userId: userLoginId,
userRoleId: "1",
kategoriApp: _.upperCase(category),
},
});
return NextResponse.json({ success: true, data: allData });
} catch (error) {
backendLogger.error("Error get data notifikasi: " + error);
}
} else {
return NextResponse.json({ success: false, message: "Method not allowed" });
}
}