upd: api tahun #9

Merged
amaliadwiy merged 1 commits from amalia/03-feb-26 into join 2026-02-03 12:25:35 +08:00
2 changed files with 17 additions and 6 deletions

View File

@@ -18,10 +18,6 @@ export async function GET(request: Request) {
const dataSkip = Number(page) * 10 - 10;
const tahun = searchParams.get("year");
const tahunFilter = tahun ? tahun : new Date().getFullYear().toString();
const startTahun = new Date(`${tahunFilter}-01-01T00:00:00.000Z`);
const endTahun = new Date(`${parseInt(tahunFilter) + 1}-01-01T00:00:00.000Z`);
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
@@ -38,6 +34,15 @@ export async function GET(request: Request) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 200 });
}
let tahunFilter = String(tahun)
if (tahunFilter == "null" || tahunFilter == undefined || tahunFilter == "" || tahunFilter == "undefined") {
tahunFilter = new Date().getFullYear().toString();
}
const startTahun = new Date(`${tahunFilter}-01-01T00:00:00.000Z`);
const endTahun = new Date(`${parseInt(tahunFilter) + 1}-01-01T00:00:00.000Z`);
const data = await prisma.divisionProject.findMany({
skip: dataSkip,
take: 10,
@@ -104,7 +109,7 @@ export async function GET(request: Request) {
}
})
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: formatData, total: totalData }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: formatData, tahun: tahunFilter, total: totalData }, { status: 200 });
} catch (error) {
console.error(error);

View File

@@ -35,7 +35,13 @@ export async function GET(request: Request) {
// (opsional) urutkan dari terbaru ke lama
uniqueYears.sort((a, b) => b - a);
const formattedData = uniqueYears.map(year => ({
id: String(year),
name: String(year)
}));
return NextResponse.json({ success: true, message: "Success", data: uniqueYears }, { status: 200 });
return NextResponse.json({ success: true, message: "Success", data: formattedData }, { status: 200 });
}