upd: api ai

Deskripsi:
- api ai list pengumuman
- api ai detail pengumuman
- api ai list banner : blm selesai

No Issues
This commit is contained in:
2025-09-15 17:38:13 +08:00
parent cacc8c72b3
commit 648f23c760
4 changed files with 189 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
import { prisma } from "@/module/_global";
import _ from "lodash";
import moment from "moment";
import "moment/locale/id";
import { NextResponse } from "next/server";
export const dynamic = 'force-dynamic'
// GET ALL PENGUMUMAN
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const judul = searchParams.get('q');
const page = searchParams.get('p');
const get = searchParams.get('get');
const villageId = searchParams.get('desa');
const dataSkip = page == null || page == undefined ? 0 : Number(page) * 10 - 10;
let kondisi: any = {
idVillage: String(villageId),
isActive: true,
title: {
contains: (judul == undefined || judul == null) ? "" : judul,
mode: "insensitive"
}
}
const announcements = await prisma.announcement.findMany({
skip: dataSkip,
take: (get == null || get == undefined || get == "" || _.isNaN(Number(get))) ? 10 : Number(get),
where: kondisi,
select: {
id: true,
title: true,
desc: true,
createdAt: true,
},
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 pengumuman", data: allData, }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan pengumuman, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}