diff --git a/bun.lockb b/bun.lockb index 84d65b8f..b4fe4545 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..05ba8967 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,15 @@ +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + +const __filename = fileURLToPath(import.meta.url); +const dirname = dirname(filename); + +const compat = new FlatCompat({ + baseDirectory: __dirname, +}); + +const eslintConfig = [ + ...compat.extends("next/core-web-vitals", "next/typescript"), +]; + +export default eslintConfig; diff --git a/package.json b/package.json index 7409eacf..9e799152 100644 --- a/package.json +++ b/package.json @@ -102,5 +102,8 @@ "winston": "^3.17.0", "winston-daily-rotate-file": "^5.0.0", "yaml": "^2.3.2" + }, + "devDependencies": { + "@eslint/eslintrc": "^3.2.0" } } diff --git a/push-staging.wibu b/push-staging.wibu new file mode 100644 index 00000000..dd700a4b --- /dev/null +++ b/push-staging.wibu @@ -0,0 +1,3 @@ +git add -A +git commit -m "data auto" +git push origin bagas/10-feb-25 diff --git a/src/app/api/admin/donasi/dashboard/kategori/route.ts b/src/app/api/admin/donasi/dashboard/kategori/route.ts index ed0063d8..effebab1 100644 --- a/src/app/api/admin/donasi/dashboard/kategori/route.ts +++ b/src/app/api/admin/donasi/dashboard/kategori/route.ts @@ -1,39 +1,25 @@ import { prisma } from "@/app/lib"; -import backendLogger from "@/util/backendLogger"; -import _ from "lodash"; import { NextResponse } from "next/server"; -export async function GET(request: Request) { - const method = request.method; - if (method !== 'GET') { - return NextResponse.json({ - success: false, - message: 'Method not allowed', - }, - { status: 405 } - ) - } - - try { - let fixData; - fixData = await prisma.donasiMaster_Kategori.count({}); - return NextResponse.json({ - success: true, - message: 'Success get data donasi dashboard', - data: fixData - }, - { status: 200 } - ) - } catch (error) { - backendLogger.error('Error get data donasi dashboard >>', error); - return NextResponse.json({ - success: false, - message: 'Error get data donasi dashboard', - reason: (error as Error).message - }, - { status: 500 } - ) - } finally { - await prisma.$disconnect(); - } -} \ No newline at end of file +export async function GET() { + try { + const fixData = await prisma.donasiMaster_Kategori.count({}); + return NextResponse.json( + { + success: true, + message: "Success get data donasi dashboard", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { + success: true, + message: "gagal mendapatkan data donasi dashboard", + error: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/admin/event/dashboard/tipe-acara/route.ts b/src/app/api/admin/event/dashboard/tipe-acara/route.ts index e4d22fdf..86648848 100644 --- a/src/app/api/admin/event/dashboard/tipe-acara/route.ts +++ b/src/app/api/admin/event/dashboard/tipe-acara/route.ts @@ -3,18 +3,9 @@ import backendLogger from "@/util/backendLogger"; import _ from "lodash"; import { NextResponse } from "next/server"; -export async function GET(request: Request) { - const method = request.method; - if (method !== "GET") { - return NextResponse.json( - { success: false, message: "Method not allowed" }, - { status: 405 } - ); - } - +export async function GET() { try { - let fixData; - fixData = await prisma.eventMaster_TipeAcara.count({ + const fixData = await prisma.eventMaster_TipeAcara.count({ where: { active: true, }, @@ -38,7 +29,5 @@ export async function GET(request: Request) { }, { status: 500 } ); - } finally { - await prisma.$disconnect(); } } diff --git a/src/app/api/admin/forum/dashboard/publish/route.ts b/src/app/api/admin/forum/dashboard/publish/route.ts index f69c6f0d..316e6a24 100644 --- a/src/app/api/admin/forum/dashboard/publish/route.ts +++ b/src/app/api/admin/forum/dashboard/publish/route.ts @@ -2,43 +2,31 @@ import { prisma } from "@/app/lib"; import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; -export async function GET(request: Request, { params }: { - params: { status: string } -}) { - const method = request.method; - if (method !== "GET") { - return NextResponse.json({ - success: false, - message: "Method not allowed", - }, - { status: 405 } - ) - } - try { - let fixData; - fixData = await prisma.forum_Posting.count({ - where: { - isActive: true, - } - }) +export async function GET() { + try { + const fixData = await prisma.forum_Posting.count({ + where: { + isActive: true, + }, + }); - return NextResponse.json({ - success: true, - message: "Success get data forum dashboard", - data: fixData, - }, - { status: 200 } - ); - } catch (error) { - backendLogger.error("Error get data forum dashboard", error); - return NextResponse.json({ - success: false, - message: "Error get data forum dashboard", - reason: (error as Error).message - }, - { status: 500 } - ) - } finally { - await prisma.$disconnect(); - } -} \ No newline at end of file + return NextResponse.json( + { + success: true, + message: "Success get data forum dashboard", + data: fixData, + }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get data forum dashboard", error); + return NextResponse.json( + { + success: false, + message: "Error get data forum dashboard", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/lib/prisma.ts b/src/app/lib/prisma.ts index b4f18d46..ccd8945e 100644 --- a/src/app/lib/prisma.ts +++ b/src/app/lib/prisma.ts @@ -1,30 +1,44 @@ -import { useDisclosure } from "@mantine/hooks"; -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from '@prisma/client'; -// Singleton PrismaClient untuk pengembangan -const globalForPrisma = globalThis as unknown as { - __prisma__: PrismaClient | undefined; -}; +let prisma: PrismaClient; -export const prisma = - globalForPrisma.__prisma__ ?? - new PrismaClient({ - // log: process.env.NODE_ENV === 'development' ? ['query', 'info', 'warn', 'error'] : [], - }); - -// Gunakan PrismaClient yang sama jika sudah ada -if (process.env.NODE_ENV !== "production") { - if (!globalForPrisma.__prisma__) { - console.log("PrismaClient initialized in development mode"); - } - globalForPrisma.__prisma__ = prisma; +if (process.env.NODE_ENV === 'production') { + prisma = new PrismaClient(); +} else { + const globalWithPrisma = global as typeof globalThis & { + prisma: PrismaClient; + }; + if (!globalWithPrisma.prisma) { + globalWithPrisma.prisma = new PrismaClient(); + } + prisma = globalWithPrisma.prisma; } -process.on("SIGINT", async () => { - // console.log("Start in Disconnecting PrismaClient..."); - const disconnect = await prisma.$disconnect(); - // console.log("End of Disconnecting PrismaClient...", disconnect); - process.exit(0); +// Handle uncaught errors +process.on('uncaughtException', async (error) => { + console.error('Uncaught Exception:', error); + await prisma.$disconnect(); + process.exit(1); }); -export default prisma; +// Handle unhandled promise rejections +process.on('unhandledRejection', async (error) => { + console.error('Unhandled Rejection:', error); + await prisma.$disconnect(); + process.exit(1); +}); + +// Handle graceful shutdown +process.on('SIGINT', async () => { + console.log('Received SIGINT signal. Closing database connections...'); + await prisma.$disconnect(); + process.exit(0); +}); + +process.on('SIGTERM', async () => { + console.log('Received SIGTERM signal. Closing database connections...'); + await prisma.$disconnect(); + process.exit(0); +}); + +export default prisma; \ No newline at end of file