fix notifikasi
deskripsi: - fix load data notifikasi: semua, event, job, donasi, investasi
This commit is contained in:
39
src/app/api/notifikasi/donasi/transaksi/[id]/route.ts
Normal file
39
src/app/api/notifikasi/donasi/transaksi/[id]/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const { id } = params;
|
||||
console.log("id server", id);
|
||||
const data = await prisma.donasi_Invoice.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
// DonasiMaster_Status: true,
|
||||
DonasiMaster_StatusInvoice: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil di check transaksis donasi",
|
||||
statusTransaksi: _.lowerCase(data?.DonasiMaster_StatusInvoice?.name),
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Gagal di check transaksis donasi",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
89
src/app/api/notifikasi/kategori/[name]/route.ts
Normal file
89
src/app/api/notifikasi/kategori/[name]/route.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
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,
|
||||
{ params }: { params: { name: string } }
|
||||
) {
|
||||
try {
|
||||
let fixData;
|
||||
const { name } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = searchParams.get("page");
|
||||
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
if (!userLoginId)
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "User not found" },
|
||||
{ status: 404 }
|
||||
);
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.notifikasi.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
isRead: "asc",
|
||||
},
|
||||
{ createdAt: "desc" },
|
||||
],
|
||||
where: {
|
||||
userId: userLoginId,
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const fixNameKategori = _.startCase(name);
|
||||
if (fixNameKategori === "Semua") {
|
||||
fixData = await prisma.notifikasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
isRead: "asc",
|
||||
},
|
||||
{ createdAt: "desc" },
|
||||
],
|
||||
where: {
|
||||
userId: userLoginId,
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
fixData = await prisma.notifikasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
isRead: "asc",
|
||||
},
|
||||
{ createdAt: "desc" },
|
||||
],
|
||||
where: {
|
||||
userId: userLoginId,
|
||||
userRoleId: "1",
|
||||
kategoriApp: _.upperCase(name),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, data: fixData, message: "Berhasil mendapatkan data" },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data notifikasi: " + error);
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal mendapatkan data" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
88
src/app/api/notifikasi/kategori/route.ts
Normal file
88
src/app/api/notifikasi/kategori/route.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
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,
|
||||
) {
|
||||
try {
|
||||
let fixData;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category") as ICategoryapp;
|
||||
const page = searchParams.get("page");
|
||||
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
if (!userLoginId)
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "User not found" },
|
||||
{ status: 404 }
|
||||
);
|
||||
|
||||
if (!page) {
|
||||
fixData = await prisma.notifikasi.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
isRead: "asc",
|
||||
},
|
||||
{ createdAt: "desc" },
|
||||
],
|
||||
where: {
|
||||
userId: userLoginId,
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const fixNameKategori = _.startCase(category);
|
||||
if (fixNameKategori === "Semua") {
|
||||
fixData = await prisma.notifikasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
isRead: "asc",
|
||||
},
|
||||
{ createdAt: "desc" },
|
||||
],
|
||||
where: {
|
||||
userId: userLoginId,
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
fixData = 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: fixData, message: "Berhasil mendapatkan data" },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data notifikasi: " + error);
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal mendapatkan data" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user