Fix notifikasi API for mobile
Fix: modified: src/app/api/mobile/notification/[id]/route.ts modified: src/app/api/mobile/notification/[id]/unread-count/route.ts modified: src/app/api/mobile/notification/route.ts ### No Issue
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
@@ -8,33 +9,22 @@ export async function GET(
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
let fixData;
|
||||
const fixCategory = _.upperCase(category || "");
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
});
|
||||
|
||||
if (category === "count-as-unread") {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
where: {
|
||||
userId: id,
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data.length;
|
||||
} else if (category === "all") {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
where: {
|
||||
userId: id,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Invalid category",
|
||||
});
|
||||
}
|
||||
fixData = data;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
@@ -47,3 +37,31 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
await prisma.notifikasi.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
isRead: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notifications marked as read",
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export async function GET(
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
console.log("User ID:", id);
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.count({
|
||||
@@ -28,7 +29,3 @@ export async function GET(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
type Pilihan = "PENGIRIM" | "PENERIMA";
|
||||
|
||||
const data: Pilihan = "PENERIMA";
|
||||
|
||||
Reference in New Issue
Block a user