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
82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
|
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
|
import { prisma } from "@/lib";
|
|
import backendLogger from "@/util/backendLogger";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export { POST };
|
|
|
|
async function POST(request: Request) {
|
|
if (request.method !== "POST") {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Method not allowed",
|
|
},
|
|
{ status: 405 }
|
|
);
|
|
}
|
|
|
|
try {
|
|
const { data } = await request.json();
|
|
const userLoginId = await funGetUserIdByToken();
|
|
|
|
if (!userLoginId) {
|
|
backendLogger.error("User tidak terautentikasi");
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "User tidak terautentikasi",
|
|
},
|
|
{ status: 400 }
|
|
); // Validasi user login
|
|
}
|
|
|
|
const existingEmail = await prisma.profile.findUnique({
|
|
where: {
|
|
email: data.email,
|
|
},
|
|
});
|
|
|
|
if (existingEmail) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Email telah digunakan",
|
|
},
|
|
{ status: 409 }
|
|
);
|
|
}
|
|
|
|
const createProfile = await prisma.profile.create({
|
|
data: {
|
|
userId: userLoginId,
|
|
name: data.name,
|
|
email: data.email,
|
|
alamat: data.alamat,
|
|
jenisKelamin: data.jenisKelamin,
|
|
imageId: data.imageId,
|
|
imageBackgroundId: data.imageBackgroundId,
|
|
},
|
|
});
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
message: "Berhasil membuat profile",
|
|
data: createProfile,
|
|
},
|
|
{ status: 201 }
|
|
);
|
|
} catch (error) {
|
|
backendLogger.error("Error create profile", error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Gagal membuat profile",
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|