feature: notifikasi pengumuman setelah login

Deskripsi:
- ui notification announcement
- api findmany notification announcement
- nb : masih setiap reload home tampil (seharusnya setelah login aja)

No Issues
This commit is contained in:
amel
2025-04-07 17:16:01 +08:00
parent ad0736e7ca
commit def1dfe660
5 changed files with 120 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import _ from "lodash";
import moment from "moment";
import "moment/locale/id";
import { NextResponse } from "next/server";
// GET ONE NOTIFIKASI PENGUMUMAN
export async function GET(request: Request) {
try {
const user = await funGetUserByCookies();
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const announcements = await prisma.notifications.findMany({
skip: 0,
take: 1,
where: {
isActive: true,
idUserTo: user.id,
isRead: false,
category: 'announcement'
},
orderBy: [
{
createdAt: 'desc'
}
]
});
const allData = announcements.map((v: any) => ({
..._.omit(v, ["createdAt"]),
createdAt: moment(v.createdAt).format("ll")
}))
return NextResponse.json({ success: true, message: "Berhasil mendapatkan notifikasi", data: allData, }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}