revisi: api filter tahun
Deskripsi: - api filter tahun project dan tugas divisi No Issues
This commit is contained in:
@@ -33,13 +33,21 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (kategori == "jumlah") {
|
if (kategori == "jumlah") {
|
||||||
|
const 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 tugas = await prisma.divisionProject.count({
|
const tugas = await prisma.divisionProject.count({
|
||||||
where: {
|
where: {
|
||||||
idDivision: String(id),
|
idDivision: String(id),
|
||||||
status: {
|
status: {
|
||||||
lte: 1
|
lte: 1
|
||||||
},
|
},
|
||||||
isActive: true
|
isActive: true,
|
||||||
|
createdAt: {
|
||||||
|
gte: startTahun,
|
||||||
|
lt: endTahun
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export async function GET(request: Request) {
|
|||||||
const name = searchParams.get('search');
|
const name = searchParams.get('search');
|
||||||
const status = searchParams.get('status');
|
const status = searchParams.get('status');
|
||||||
const idGroup = searchParams.get("group");
|
const idGroup = searchParams.get("group");
|
||||||
|
const tahun = searchParams.get("year");
|
||||||
const page = searchParams.get('page');
|
const page = searchParams.get('page');
|
||||||
const kategori = searchParams.get('cat');
|
const kategori = searchParams.get('cat');
|
||||||
const user = searchParams.get('user');
|
const user = searchParams.get('user');
|
||||||
@@ -30,6 +31,9 @@ export async function GET(request: Request) {
|
|||||||
const roleUser = userMobile.idUserRole
|
const roleUser = userMobile.idUserRole
|
||||||
const villageId = userMobile.idVillage
|
const villageId = userMobile.idVillage
|
||||||
const userId = userMobile.id
|
const userId = userMobile.id
|
||||||
|
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`);
|
||||||
|
|
||||||
if (idGroup == "null" || idGroup == undefined || idGroup == "" || idGroup == "undefined") {
|
if (idGroup == "null" || idGroup == undefined || idGroup == "" || idGroup == "undefined") {
|
||||||
grup = userMobile.idGroup
|
grup = userMobile.idGroup
|
||||||
@@ -58,7 +62,11 @@ export async function GET(request: Request) {
|
|||||||
contains: (name == undefined || name == "null") ? "" : name,
|
contains: (name == undefined || name == "null") ? "" : name,
|
||||||
mode: "insensitive"
|
mode: "insensitive"
|
||||||
},
|
},
|
||||||
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0
|
status: (status == "0" || status == "1" || status == "2" || status == "3") ? Number(status) : 0,
|
||||||
|
createdAt: {
|
||||||
|
gte: startTahun,
|
||||||
|
lt: endTahun
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +86,10 @@ export async function GET(request: Request) {
|
|||||||
some: {
|
some: {
|
||||||
idUser: String(userId)
|
idUser: String(userId)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
gte: startTahun,
|
||||||
|
lt: endTahun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
src/app/api/mobile/project/tahun/route.ts
Normal file
41
src/app/api/mobile/project/tahun/route.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { prisma } from "@/module/_global";
|
||||||
|
import { funGetUserById } from "@/module/auth";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const user = searchParams.get('user');
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const villageId = userMobile.idVillage
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
|
const data = await prisma.project.findMany({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idVillage: villageId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
createdAt: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataYear = data.map((item: any) => item.createdAt.getFullYear())
|
||||||
|
// Hapus duplikat pakai Set
|
||||||
|
const uniqueYears = [...new Set(dataYear)];
|
||||||
|
|
||||||
|
// Tambahkan tahun sekarang kalau belum ada
|
||||||
|
if (!uniqueYears.includes(currentYear)) {
|
||||||
|
uniqueYears.push(currentYear);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (opsional) urutkan dari terbaru ke lama
|
||||||
|
uniqueYears.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Success", data: uniqueYears }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
@@ -16,6 +16,11 @@ export async function GET(request: Request) {
|
|||||||
const page = searchParams.get('page');
|
const page = searchParams.get('page');
|
||||||
const user = searchParams.get('user');
|
const user = searchParams.get('user');
|
||||||
const dataSkip = Number(page) * 10 - 10;
|
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) })
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
@@ -43,6 +48,10 @@ export async function GET(request: Request) {
|
|||||||
title: {
|
title: {
|
||||||
contains: (name == undefined || name == "null") ? "" : name,
|
contains: (name == undefined || name == "null") ? "" : name,
|
||||||
mode: "insensitive"
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
gte: startTahun,
|
||||||
|
lt: endTahun
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
@@ -87,6 +96,10 @@ export async function GET(request: Request) {
|
|||||||
title: {
|
title: {
|
||||||
contains: (name == undefined || name == "null") ? "" : name,
|
contains: (name == undefined || name == "null") ? "" : name,
|
||||||
mode: "insensitive"
|
mode: "insensitive"
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
gte: startTahun,
|
||||||
|
lt: endTahun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
41
src/app/api/mobile/task/tahun/route.ts
Normal file
41
src/app/api/mobile/task/tahun/route.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { prisma } from "@/module/_global";
|
||||||
|
import { funGetUserById } from "@/module/auth";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const user = searchParams.get('user');
|
||||||
|
const divisi = searchParams.get('division');
|
||||||
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
|
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.divisionProject.findMany({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: String(divisi),
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
createdAt: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataYear = data.map((item: any) => item.createdAt.getFullYear())
|
||||||
|
// Hapus duplikat pakai Set
|
||||||
|
const uniqueYears = [...new Set(dataYear)];
|
||||||
|
|
||||||
|
// Tambahkan tahun sekarang kalau belum ada
|
||||||
|
if (!uniqueYears.includes(currentYear)) {
|
||||||
|
uniqueYears.push(currentYear);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (opsional) urutkan dari terbaru ke lama
|
||||||
|
uniqueYears.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Success", data: uniqueYears }, { status: 200 });
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user