data auto

This commit is contained in:
2025-02-10 17:53:13 +08:00
parent 7445e8bb3a
commit 1df244402b
8 changed files with 110 additions and 112 deletions

BIN
bun.lockb

Binary file not shown.

15
eslint.config.mjs Normal file
View File

@@ -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;

View File

@@ -102,5 +102,8 @@
"winston": "^3.17.0", "winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0", "winston-daily-rotate-file": "^5.0.0",
"yaml": "^2.3.2" "yaml": "^2.3.2"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0"
} }
} }

3
push-staging.wibu Normal file
View File

@@ -0,0 +1,3 @@
git add -A
git commit -m "data auto"
git push origin staging

View File

@@ -1,39 +1,25 @@
import { prisma } from "@/app/lib"; import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET() {
const method = request.method;
if (method !== 'GET') {
return NextResponse.json({
success: false,
message: 'Method not allowed',
},
{ status: 405 }
)
}
try { try {
let fixData; const fixData = await prisma.donasiMaster_Kategori.count({});
fixData = await prisma.donasiMaster_Kategori.count({}); return NextResponse.json(
return NextResponse.json({ {
success: true, success: true,
message: 'Success get data donasi dashboard', message: "Success get data donasi dashboard",
data: fixData data: fixData,
}, },
{ status: 200 } { status: 200 }
) );
} catch (error) { } catch (error) {
backendLogger.error('Error get data donasi dashboard >>', error); return NextResponse.json(
return NextResponse.json({ {
success: false, success: true,
message: 'Error get data donasi dashboard', message: "gagal mendapatkan data donasi dashboard",
reason: (error as Error).message error: (error as Error).message,
}, },
{ status: 500 } { status: 500 }
) );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -3,18 +3,9 @@ import backendLogger from "@/util/backendLogger";
import _ from "lodash"; import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET() {
const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try { try {
let fixData; const fixData = await prisma.eventMaster_TipeAcara.count({
fixData = await prisma.eventMaster_TipeAcara.count({
where: { where: {
active: true, active: true,
}, },
@@ -38,7 +29,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -2,27 +2,16 @@ import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger"; import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET() {
params: { status: string }
}) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
try { try {
let fixData; const fixData = await prisma.forum_Posting.count({
fixData = await prisma.forum_Posting.count({
where: { where: {
isActive: true, isActive: true,
} },
}) });
return NextResponse.json({ return NextResponse.json(
{
success: true, success: true,
message: "Success get data forum dashboard", message: "Success get data forum dashboard",
data: fixData, data: fixData,
@@ -31,14 +20,13 @@ export async function GET(request: Request, { params }: {
); );
} catch (error) { } catch (error) {
backendLogger.error("Error get data forum dashboard", error); backendLogger.error("Error get data forum dashboard", error);
return NextResponse.json({ return NextResponse.json(
{
success: false, success: false,
message: "Error get data forum dashboard", message: "Error get data forum dashboard",
reason: (error as Error).message reason: (error as Error).message,
}, },
{ status: 500 } { status: 500 }
) );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -1,29 +1,43 @@
import { useDisclosure } from "@mantine/hooks"; import { PrismaClient } from '@prisma/client';
import { PrismaClient } from "@prisma/client";
// Singleton PrismaClient untuk pengembangan let prisma: PrismaClient;
const globalForPrisma = globalThis as unknown as {
__prisma__: PrismaClient | undefined; 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;
}
export const prisma = // Handle uncaught errors
globalForPrisma.__prisma__ ?? process.on('uncaughtException', async (error) => {
new PrismaClient({ console.error('Uncaught Exception:', error);
// log: process.env.NODE_ENV === 'development' ? ['query', 'info', 'warn', 'error'] : [], await prisma.$disconnect();
process.exit(1);
}); });
// Gunakan PrismaClient yang sama jika sudah ada // Handle unhandled promise rejections
if (process.env.NODE_ENV !== "production") { process.on('unhandledRejection', async (error) => {
if (!globalForPrisma.__prisma__) { console.error('Unhandled Rejection:', error);
console.log("PrismaClient initialized in development mode"); await prisma.$disconnect();
} process.exit(1);
globalForPrisma.__prisma__ = prisma; });
}
process.on("SIGINT", async () => { // Handle graceful shutdown
// console.log("Start in Disconnecting PrismaClient..."); process.on('SIGINT', async () => {
const disconnect = await prisma.$disconnect(); console.log('Received SIGINT signal. Closing database connections...');
// console.log("End of Disconnecting PrismaClient...", disconnect); await prisma.$disconnect();
process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('Received SIGTERM signal. Closing database connections...');
await prisma.$disconnect();
process.exit(0); process.exit(0);
}); });