Fix notifikasi
Deskripsi: - Ganti get notifikasi dengan API
This commit is contained in:
63
src/app/api/notifikasi/get-all-by-category/route.ts
Normal file
63
src/app/api/notifikasi/get-all-by-category/route.ts
Normal 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" });
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
import { Notifikasi_UiEvent } from "@/app_modules/notifikasi/_ui";
|
||||
import notifikasi_getByUserId from "@/app_modules/notifikasi/fun/get/get_notifiaksi_by_id";
|
||||
|
||||
export default async function Page() {
|
||||
const listNotifikasi = await notifikasi_getByUserId({
|
||||
page: 1,
|
||||
kategoriApp: "Event",
|
||||
});
|
||||
//
|
||||
|
||||
return (
|
||||
<>
|
||||
<Notifikasi_UiEvent listNotifikasi={listNotifikasi} />
|
||||
<Notifikasi_UiEvent />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { Notifikasi_UiAll } from "@/app_modules/notifikasi/_ui";
|
||||
import notifikasi_getByUserId from "@/app_modules/notifikasi/fun/get/get_notifiaksi_by_id";
|
||||
|
||||
export default async function Page() {
|
||||
const listNotifikasi = await notifikasi_getByUserId({
|
||||
page: 1,
|
||||
kategoriApp: "Semua",
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<Notifikasi_UiAll listNotifikasi={listNotifikasi} />
|
||||
<Notifikasi_UiAll />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
11
src/app/lib/api_user_router/route_api_notifikasi.ts
Normal file
11
src/app/lib/api_user_router/route_api_notifikasi.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ICategoryapp } from "@/app_modules/notifikasi/model/interface";
|
||||
|
||||
export const API_RouteNotifikasi = {
|
||||
get_all_by_category: ({
|
||||
category,
|
||||
page,
|
||||
}: {
|
||||
category: ICategoryapp;
|
||||
page: number;
|
||||
}) => `/api/notifikasi/get-all-by-category?category=${category}&page=${page}`,
|
||||
};
|
||||
Reference in New Issue
Block a user