fix: Implementasi retry mechanism dan error handling untuk database connections Deskripsi: Menambahkan withRetry wrapper pada berbagai API routes untuk menangani transient database errors dan meningkatkan reliabilitas koneksi Memperbaiki error handling pada notification, authentication, dan user validation endpoints dengan response 503 untuk database connection errors Update prisma.ts dengan konfigurasi logging yang lebih baik dan datasources configuration Menambahkan validasi input parameters pada beberapa endpoints Update dokumentasi QWEN.md dengan commit message format dan comment standards Update .env.example dengan connection pool settings yang lebih lengkap File yang diubah: src/lib/prisma.ts — Konfigurasi Prisma client & logging src/app/api/admin/notifikasi/count/route.tsx src/app/api/auth/mobile-login/route.ts src/app/api/mobile/notification/[id]/route.ts src/app/api/user-validate/route.ts Dan 27 file API routes lainnya (penerapan withRetry secara konsisten) QWEN.md — Dokumentasi commit & comment standards .env.example — Database connection pool configuration ### No Issue
103 lines
2.3 KiB
TypeScript
103 lines
2.3 KiB
TypeScript
import { prisma } from "@/lib";
|
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
|
import { IEventSponsor } from "@/app_modules/event/_lib/interface";
|
|
import backendLogger from "@/util/backendLogger";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
context: { params: { id: string } }
|
|
) {
|
|
const method = request.method;
|
|
if (method !== "POST") {
|
|
return NextResponse.json(
|
|
{ success: false, message: "Method not allowed" },
|
|
{ status: 405 }
|
|
);
|
|
}
|
|
|
|
const userLoginId = await funGetUserIdByToken();
|
|
|
|
if (!userLoginId) {
|
|
return NextResponse.json(
|
|
{ success: false, message: "User not found" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
try {
|
|
let fixData;
|
|
const { id } = context.params;
|
|
const req: IEventSponsor = await request.json();
|
|
|
|
fixData = await prisma.eventSponsor.create({
|
|
data: {
|
|
eventId: id,
|
|
name: req.name as string,
|
|
fileName: req.fileName as string,
|
|
fileExt: req.fileExt as string,
|
|
fileId: req.fileId as string,
|
|
// authorId: userLoginId,
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: "Success create sponsor",
|
|
});
|
|
} catch (error) {
|
|
backendLogger.error("Error create sponsor event", error);
|
|
return NextResponse.json(
|
|
{ success: false, message: "Failed create sponsor" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function GET(
|
|
request: Request,
|
|
context: { params: { id: string } }
|
|
) {
|
|
const method = request.method;
|
|
if (method !== "GET") {
|
|
return NextResponse.json(
|
|
{ success: false, message: "Method not allowed" },
|
|
{ status: 405 }
|
|
);
|
|
}
|
|
|
|
try {
|
|
let fixData;
|
|
const { id } = context.params;
|
|
|
|
fixData = await prisma.eventSponsor.findUnique({
|
|
where: {
|
|
id: id,
|
|
},
|
|
include: {
|
|
Author: {
|
|
include: {
|
|
Profile: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: "Success create sponsor",
|
|
data: fixData,
|
|
});
|
|
} catch (error) {
|
|
backendLogger.error("Error get sponsor event", error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Failed create sponsor",
|
|
reason: (error as Error).message,
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|