Compare commits

..

4 Commits

8 changed files with 186 additions and 176 deletions

View File

@@ -81,10 +81,17 @@ const Utils = new Elysia({
if (!process.env.WIBU_UPLOAD_DIR) if (!process.env.WIBU_UPLOAD_DIR)
throw new Error("WIBU_UPLOAD_DIR is not defined"); throw new Error("WIBU_UPLOAD_DIR is not defined");
const ApiServer = new Elysia() const ApiServer = new Elysia({ prefix: "/api" })
.use(
staticPlugin({
assets: UPLOAD_DIR,
prefix: "/uploads",
}),
)
.use(cors(corsConfig))
.use( .use(
swagger({ swagger({
path: "/api/docs", path: "/docs",
documentation: { documentation: {
info: { info: {
title: "Desa Darmasaba API Documentation", title: "Desa Darmasaba API Documentation",
@@ -93,13 +100,6 @@ const ApiServer = new Elysia()
}, },
}), }),
) )
.use(
staticPlugin({
assets: UPLOAD_DIR,
prefix: "/uploads",
}),
)
.use(cors(corsConfig))
.onError(({ code }) => { .onError(({ code }) => {
if (code === "NOT_FOUND") { if (code === "NOT_FOUND") {
return { return {
@@ -108,131 +108,128 @@ const ApiServer = new Elysia()
}; };
} }
}) })
.group("/api", (app) => .use(Utils)
app .use(FileStorage)
.use(Utils) .use(LandingPage)
.use(FileStorage) .use(PPID)
.use(LandingPage) .use(Desa)
.use(PPID) .use(Kesehatan)
.use(Desa) .use(Keamanan)
.use(Kesehatan) .use(Ekonomi)
.use(Keamanan) .use(Inovasi)
.use(Ekonomi) .use(Lingkungan)
.use(Inovasi) .use(Pendidikan)
.use(Lingkungan) .use(User)
.use(Pendidikan) .use(Role)
.use(User) .use(Search)
.use(Role) .get("/layanan", layanan)
.use(Search) .get("/potensi", getPotensi)
.get("/layanan", layanan) .get(
.get("/potensi", getPotensi) "/img/:name",
.get( ({ params, query }) => {
"/img/:name", return img({
({ params, query }) => { name: params.name,
return img({ UPLOAD_DIR_IMAGE,
name: params.name, ROOT,
UPLOAD_DIR_IMAGE, size: query.size,
ROOT, });
size: query.size, },
}); {
}, params: t.Object({
{ name: t.String(),
params: t.Object({ }),
name: t.String(), query: t.Optional(
}), t.Object({
query: t.Optional( size: t.Optional(t.Number()),
t.Object({ }),
size: t.Optional(t.Number()),
}),
),
},
)
.delete(
"/img/:name",
({ params }) => {
return imgDel({
name: params.name,
UPLOAD_DIR_IMAGE,
});
},
{
params: t.Object({
name: t.String(),
}),
},
)
.get(
"/imgs",
({ query }) => {
return imgs({
search: query.search,
page: query.page,
count: query.count,
UPLOAD_DIR_IMAGE,
});
},
{
query: t.Optional(
t.Object({
page: t.Number({ default: 1 }),
count: t.Number({ default: 10 }),
search: t.String({ default: "" }),
}),
),
},
)
.post(
"/upl-img",
({ body }) => {
console.log(body.title);
return uplImg({ files: body.files, UPLOAD_DIR_IMAGE });
},
{
body: t.Object({
title: t.String(),
files: t.Files({ multiple: true }),
}),
},
)
.post(
"/upl-img-single",
({ body }) => {
return uplImgSingle({
fileName: body.name,
file: body.file,
UPLOAD_DIR_IMAGE,
});
},
{
body: t.Object({
name: t.String(),
file: t.File(),
}),
},
)
.post(
"/upl-csv-single",
({ body }) => {
return uplCsvSingle({ fileName: body.name, file: body.file });
},
{
body: t.Object({
name: t.String(),
file: t.File(),
}),
},
)
.post(
"/upl-csv",
({ body }) => {
return uplCsv({ files: body.files });
},
{
body: t.Object({
files: t.Files(),
}),
},
), ),
},
)
.delete(
"/img/:name",
({ params }) => {
return imgDel({
name: params.name,
UPLOAD_DIR_IMAGE,
});
},
{
params: t.Object({
name: t.String(),
}),
},
)
.get(
"/imgs",
({ query }) => {
return imgs({
search: query.search,
page: query.page,
count: query.count,
UPLOAD_DIR_IMAGE,
});
},
{
query: t.Optional(
t.Object({
page: t.Number({ default: 1 }),
count: t.Number({ default: 10 }),
search: t.String({ default: "" }),
}),
),
},
)
.post(
"/upl-img",
({ body }) => {
console.log(body.title);
return uplImg({ files: body.files, UPLOAD_DIR_IMAGE });
},
{
body: t.Object({
title: t.String(),
files: t.Files({ multiple: true }),
}),
},
)
.post(
"/upl-img-single",
({ body }) => {
return uplImgSingle({
fileName: body.name,
file: body.file,
UPLOAD_DIR_IMAGE,
});
},
{
body: t.Object({
name: t.String(),
file: t.File(),
}),
},
)
.post(
"/upl-csv-single",
({ body }) => {
return uplCsvSingle({ fileName: body.name, file: body.file });
},
{
body: t.Object({
name: t.String(),
file: t.File(),
}),
},
)
.post(
"/upl-csv",
({ body }) => {
return uplCsv({ files: body.files });
},
{
body: t.Object({
files: t.Files(),
}),
},
); );
export const GET = ApiServer.handle; export const GET = ApiServer.handle;

View File

@@ -33,6 +33,8 @@ export async function POST(req: Request) {
const codeOtp = randomOTP(); const codeOtp = randomOTP();
const otpNumber = Number(codeOtp); const otpNumber = Number(codeOtp);
console.log(`🔑 DEBUG OTP [${nomor}]: ${codeOtp}`);
const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`; const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`; const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`;
@@ -40,26 +42,19 @@ export async function POST(req: Request) {
try { try {
const res = await fetch(waUrl); const res = await fetch(waUrl);
const sendWa = await res.json(); if (!res.ok) {
console.log("📱 WA Response:", sendWa); console.error(`⚠️ WA Service HTTP Error: ${res.status} ${res.statusText}. Continuing since OTP is logged.`);
console.log(`💡 Use this OTP to login: ${codeOtp}`);
if (sendWa.status !== "success") { } else {
console.error("❌ WA Service Error:", sendWa); const sendWa = await res.json();
return NextResponse.json( console.log("📱 WA Response:", sendWa);
{ if (sendWa.status !== "success") {
success: false, console.error("⚠️ WA Service Logic Error:", sendWa);
message: "Gagal mengirim OTP via WhatsApp", }
debug: sendWa
},
{ status: 400 }
);
} }
} catch (waError) { } catch (waError: unknown) {
console.error("❌ Fetch WA Error:", waError); const errorMessage = waError instanceof Error ? waError.message : String(waError);
return NextResponse.json( console.error("⚠️ WA Connection Exception. Continuing since OTP is logged.", errorMessage);
{ success: false, message: "Terjadi kesalahan saat mengirim WA" },
{ status: 500 }
);
} }
const createOtpId = await prisma.kodeOtp.create({ const createOtpId = await prisma.kodeOtp.create({

View File

@@ -22,14 +22,22 @@ export async function POST(req: Request) {
// ✅ Generate dan kirim OTP // ✅ Generate dan kirim OTP
const codeOtp = randomOTP(); const codeOtp = randomOTP();
const otpNumber = Number(codeOtp); const otpNumber = Number(codeOtp);
console.log(`🔑 DEBUG REGISTER OTP [${nomor}]: ${codeOtp}`);
const waMessage = `Website Desa Darmasaba - Kode verifikasi Anda: ${codeOtp}`; const waMessage = `Website Desa Darmasaba - Kode verifikasi Anda: ${codeOtp}`;
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`; const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`;
const waRes = await fetch(waUrl);
const waData = await waRes.json(); try {
const waRes = await fetch(waUrl);
if (waData.status !== "success") { if (!waRes.ok) {
return NextResponse.json({ success: false, message: 'Gagal mengirim OTP via WhatsApp' }, { status: 400 }); console.warn(`⚠️ WA Service HTTP Error (Register): ${waRes.status} ${waRes.statusText}. Continuing since OTP is logged.`);
} else {
const waData = await waRes.json();
console.log("📱 WA Response (Register):", waData);
}
} catch (waError: unknown) {
const errorMessage = waError instanceof Error ? waError.message : String(waError);
console.warn("⚠️ WA Connection Exception (Register). Continuing since OTP is logged.", errorMessage);
} }
// ✅ Simpan OTP ke database // ✅ Simpan OTP ke database

View File

@@ -17,18 +17,23 @@ export async function POST(req: Request) {
const codeOtp = randomOTP(); const codeOtp = randomOTP();
const otpNumber = Number(codeOtp); const otpNumber = Number(codeOtp);
console.log(`🔑 DEBUG RESEND OTP [${nomor}]: ${codeOtp}`);
// Kirim OTP via WhatsApp // Kirim OTP via WhatsApp
const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`; const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`; const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`;
const waRes = await fetch(waUrl);
const waData = await waRes.json(); try {
const waRes = await fetch(waUrl);
if (waData.status !== "success") { if (!waRes.ok) {
return NextResponse.json( console.warn(`⚠️ WA Service HTTP Error (Resend): ${waRes.status} ${waRes.statusText}. Continuing since OTP is logged.`);
{ success: false, message: "Gagal mengirim OTP via WhatsApp" }, } else {
{ status: 400 } const waData = await waRes.json();
); console.log("📱 WA Response (Resend):", waData);
}
} catch (waError: unknown) {
const errorMessage = waError instanceof Error ? waError.message : String(waError);
console.warn("⚠️ WA Connection Exception (Resend). Continuing since OTP is logged.", errorMessage);
} }
// Simpan OTP ke database // Simpan OTP ke database

View File

@@ -21,14 +21,22 @@ export async function POST(req: Request) {
// Generate OTP // Generate OTP
const codeOtp = randomOTP(); const codeOtp = randomOTP();
const otpNumber = Number(codeOtp); const otpNumber = Number(codeOtp);
console.log(`🔑 DEBUG SEND-OTP-REGISTER [${nomor}]: ${codeOtp}`);
// Kirim WA // Kirim WA
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=Website Desa Darmasaba - Kode verifikasi Anda: ${codeOtp}`; const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=Website Desa Darmasaba - Kode verifikasi Anda: ${codeOtp}`;
const res = await fetch(waUrl);
const sendWa = await res.json(); try {
const res = await fetch(waUrl);
if (sendWa.status !== "success") { if (!res.ok) {
return NextResponse.json({ success: false, message: 'Gagal mengirim OTP' }, { status: 400 }); console.warn(`⚠️ WA Service HTTP Error (SendOTPRegister): ${res.status} ${res.statusText}. Continuing since OTP is logged.`);
} else {
const sendWa = await res.json();
console.log("📱 WA Response (SendOTPRegister):", sendWa);
}
} catch (waError: unknown) {
const errorMessage = waError instanceof Error ? waError.message : String(waError);
console.warn("⚠️ WA Connection Exception (SendOTPRegister). Continuing since OTP is logged.", errorMessage);
} }
// Simpan OTP // Simpan OTP

View File

@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ import { Paper, Title, Progress, Stack, Text, Group, Box, type MantineColor } from '@mantine/core'
import { Paper, Title, Progress, Stack, Text, Group, Box, rem } from '@mantine/core'
import { IconArrowUpRight, IconArrowDownRight } from '@tabler/icons-react' import { IconArrowUpRight, IconArrowDownRight } from '@tabler/icons-react'
import { APBDes, APBDesItem, SummaryData } from '../types/apbdes' import { APBDes, APBDesItem } from '../types/apbdes'
interface SummaryProps { interface SummaryProps {
title: string title: string
@@ -107,7 +106,7 @@ function Summary({ title, data, icon }: SummaryProps) {
<Text <Text
fz="xs" fz="xs"
c={statusMessage.color as any} c={statusMessage.color as MantineColor}
fw={600} fw={600}
style={{ style={{
backgroundColor: `var(--mantine-color-${statusMessage.color}-0)`, backgroundColor: `var(--mantine-color-${statusMessage.color}-0)`,

View File

@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Paper, Table, Title, Box, ScrollArea, Badge } from '@mantine/core' import { Paper, Table, Title, Box, ScrollArea, Badge } from '@mantine/core'
import { APBDes, APBDesItem } from '../types/apbdes' import { APBDes, APBDesItem } from '../types/apbdes'

View File

@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Paper, Table, Title, Badge, Text, Box, ScrollArea } from '@mantine/core' import { Paper, Table, Title, Badge, Text, Box, ScrollArea } from '@mantine/core'
import { APBDes, APBDesItem, RealisasiItem } from '../types/apbdes' import { APBDes, APBDesItem, RealisasiItem } from '../types/apbdes'