QC Tampilan Admin & User, Api berfungsi
This commit is contained in:
@@ -1,8 +1,49 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function demografiPekerjaanFindMany(context: Context) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || '';
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ pekerjaan: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.dataDemografiPekerjaan.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
prisma.dataDemografiPekerjaan.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
export default async function demografiPekerjaanFindMany() {
|
||||
const res = await prisma.dataDemografiPekerjaan.findMany();
|
||||
return {
|
||||
data: res
|
||||
}
|
||||
}
|
||||
success: true,
|
||||
message: "Success fetch demografi pekerjaan with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
total,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to fetch demografi pekerjaan with pagination",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,54 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function grafikJumlahPendudukMiskinFindMany(
|
||||
context: Context
|
||||
) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || "";
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
const yearSearch = Number(search);
|
||||
|
||||
where.OR = [
|
||||
// kalau search bisa diparse jadi number → cocokin year
|
||||
...(isNaN(yearSearch) ? [] : [{ year: yearSearch }]),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.grafikJumlahPendudukMiskin.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
prisma.grafikJumlahPendudukMiskin.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
export default async function grafikJumlahPendudukMiskinFindMany() {
|
||||
const res = await prisma.grafikJumlahPendudukMiskin.findMany();
|
||||
return {
|
||||
data: res,
|
||||
success: true,
|
||||
message: "Success fetch grafik jumlah penduduk miskin with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
total,
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to fetch grafik jumlah penduduk miskin with pagination",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,27 +12,33 @@ export default async function detailDataPengangguranFindMany(context: Context) {
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
const yearSearch = Number(search);
|
||||
|
||||
where.OR = [
|
||||
{ year: { contains: search, mode: "insensitive" } },
|
||||
// kalau search bisa diparse jadi number → cocokin year
|
||||
...(isNaN(yearSearch) ? [] : [{ year: yearSearch }]),
|
||||
// selalu cocokin month pakai contains
|
||||
{ month: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
try {
|
||||
const monthOrder = ["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des"];
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.detailDataPengangguran.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: [{ year: "desc" }, { month: "asc" }],
|
||||
orderBy: { year: "asc" }, // urut tahun dulu
|
||||
}),
|
||||
prisma.detailDataPengangguran.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
data.sort((a, b) => monthOrder.indexOf(a.month) - monthOrder.indexOf(b.month));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch apb desa with pagination",
|
||||
message: "Success fetch detail data pengangguran with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Context } from "elysia";
|
||||
type FormCreate = {
|
||||
nama: string;
|
||||
deskripsi: string;
|
||||
ikonUrl?: string; // optional karena boleh null
|
||||
icon: string;
|
||||
statistik?: {
|
||||
tahun: number;
|
||||
jumlah: number;
|
||||
@@ -18,7 +18,7 @@ export default async function programKemiskinanCreate(context: Context) {
|
||||
data: {
|
||||
nama: body.nama,
|
||||
deskripsi: body.deskripsi,
|
||||
ikonUrl: body.ikonUrl,
|
||||
icon: body.icon,
|
||||
statistik: body.statistik
|
||||
? {
|
||||
create: {
|
||||
|
||||
@@ -12,7 +12,7 @@ const ProgramKemiskinan = new Elysia({
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
deskripsi: t.String(),
|
||||
ikonUrl: t.String(),
|
||||
icon: t.String(),
|
||||
statistik: t.Object({
|
||||
tahun: t.String(),
|
||||
jumlah: t.String(),
|
||||
@@ -32,7 +32,7 @@ const ProgramKemiskinan = new Elysia({
|
||||
body: t.Object({
|
||||
nama: t.String(),
|
||||
deskripsi: t.String(),
|
||||
ikonUrl: t.String(),
|
||||
icon: t.String(),
|
||||
statistik: t.Object({
|
||||
tahun: t.String(),
|
||||
jumlah: t.String(),
|
||||
|
||||
@@ -5,6 +5,7 @@ type FormUpdate = {
|
||||
nama: string;
|
||||
deskripsi: string;
|
||||
ikonUrl?: string;
|
||||
icon: string;
|
||||
statistik?: {
|
||||
tahun: number;
|
||||
jumlah: number;
|
||||
@@ -51,7 +52,7 @@ export default async function programKemiskinanUpdate(context: Context) {
|
||||
data: {
|
||||
nama: body.nama,
|
||||
deskripsi: body.deskripsi,
|
||||
ikonUrl: body.ikonUrl,
|
||||
icon: body.icon,
|
||||
statistik: {
|
||||
connect: { id: statistikUpdate.id }, // konek ke statistik baru atau yang diperbarui
|
||||
},
|
||||
|
||||
@@ -1,8 +1,50 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function sektorUnggulanDesaFindMany(context: Context) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || '';
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ name: { contains: search, mode: "insensitive" } },
|
||||
{ description: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.sektorUnggulanDesa.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
prisma.sektorUnggulanDesa.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
export default async function sektorUnggulanDesaFindMany() {
|
||||
const res = await prisma.sektorUnggulanDesa.findMany();
|
||||
return {
|
||||
data: res,
|
||||
success: true,
|
||||
message: "Success fetch sektor unggulan desa with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
total,
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to fetch sektor unggulan desa with pagination",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,56 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function grafikMenganggurBerdasarkanUsiaFindMany(
|
||||
context: Context
|
||||
) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || "";
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ usia18_25: { contains: search, mode: "insensitive" } },
|
||||
{ usia26_35: { contains: search, mode: "insensitive" } },
|
||||
{ usia36_45: { contains: search, mode: "insensitive" } },
|
||||
{ usia46_keatas: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.grafikMenganggurBerdasarkanUsia.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
prisma.grafikMenganggurBerdasarkanUsia.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
export default async function grafikMenganggurBerdasarkanUsiaFindMany() {
|
||||
const res = await prisma.grafikMenganggurBerdasarkanUsia.findMany();
|
||||
return {
|
||||
data: res
|
||||
}
|
||||
}
|
||||
success: true,
|
||||
message:
|
||||
"Success fetch grafik menganggur berdasarkan usia with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
total,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {
|
||||
success: false,
|
||||
message:
|
||||
"Failed to fetch grafik menganggur berdasarkan usia with pagination",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,53 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function grafikPengangguranBerdasarkanPendidikanFindMany(context: Context) {
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || '';
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ SD: { contains: search, mode: "insensitive" } },
|
||||
{ SMP: { contains: search, mode: "insensitive" } },
|
||||
{ SMA: { contains: search, mode: "insensitive" } },
|
||||
{ D3: { contains: search, mode: "insensitive" } },
|
||||
{ S1: { contains: search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.grafikMenganggurBerdasarkanPendidikan.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
prisma.grafikMenganggurBerdasarkanPendidikan.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
export default async function grafikMenganggurBerdasarkanPendidikanFindMany() {
|
||||
const res = await prisma.grafikMenganggurBerdasarkanPendidikan.findMany();
|
||||
return {
|
||||
data: res
|
||||
}
|
||||
}
|
||||
success: true,
|
||||
message: "Success fetch grafik menganggur berdasarkan pendidikan with pagination",
|
||||
data,
|
||||
page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
total,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to fetch grafik menganggur berdasarkan pendidikan with pagination",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user