Simpan notifikasi ke database
Add: - prisma/migrations/20251218071503_add_type_on_db_notifikasi/ - src/app/api/mobile/notification/ Fix: - modified: prisma/schema.prisma - modified: src/app/api/mobile/auth/device-tokens/route.ts - deleted: src/app/api/mobile/notifications/route.ts - modified: x.sh ###No Issue
This commit is contained in:
49
src/app/api/mobile/notification/[id]/route.ts
Normal file
49
src/app/api/mobile/notification/[id]/route.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
|
||||
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",
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user