diff --git a/src/app/api/mobile/task/route.ts b/src/app/api/mobile/task/route.ts index 0533f40..784be12 100644 --- a/src/app/api/mobile/task/route.ts +++ b/src/app/api/mobile/task/route.ts @@ -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); diff --git a/src/app/api/mobile/task/tahun/route.ts b/src/app/api/mobile/task/tahun/route.ts index 3df17b4..7743729 100644 --- a/src/app/api/mobile/task/tahun/route.ts +++ b/src/app/api/mobile/task/tahun/route.ts @@ -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 }); } \ No newline at end of file