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
130 lines
2.7 KiB
TypeScript
130 lines
2.7 KiB
TypeScript
import { prisma } from "@/lib";
|
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(request: Request) {
|
|
if (request.method !== "GET") {
|
|
return NextResponse.json(
|
|
{ success: false, message: "Method Not Allowed" },
|
|
{
|
|
status: 405,
|
|
}
|
|
);
|
|
}
|
|
|
|
try {
|
|
let fixData;
|
|
const userLoginId = await funGetUserIdByToken();
|
|
if (userLoginId == null) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Gagal mendapatkan data, user id tidak ada",
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const search = searchParams.get("search");
|
|
const page = searchParams.get("page");
|
|
const takeData = 15;
|
|
const skipData = Number(page) * takeData - takeData;
|
|
|
|
if (!page) {
|
|
fixData = await prisma.user.findMany({
|
|
orderBy: {
|
|
createdAt: "desc",
|
|
},
|
|
where: {
|
|
MasterUserRole: {
|
|
name: "User",
|
|
},
|
|
active: true,
|
|
NOT: {
|
|
Profile: null,
|
|
},
|
|
Profile: {
|
|
name: {
|
|
contains: search ? search : "",
|
|
mode: "insensitive",
|
|
},
|
|
},
|
|
},
|
|
include: {
|
|
Profile: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
imageId: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
} else {
|
|
fixData = await prisma.user.findMany({
|
|
take: takeData,
|
|
skip: skipData,
|
|
orderBy: {
|
|
createdAt: "desc",
|
|
},
|
|
where: {
|
|
MasterUserRole: {
|
|
name: "User",
|
|
},
|
|
active: true,
|
|
Profile: {
|
|
name: {
|
|
contains: search ? search : "",
|
|
mode: "insensitive",
|
|
},
|
|
},
|
|
NOT: {
|
|
Profile: null,
|
|
},
|
|
// OR: [
|
|
// {
|
|
// NOT: {
|
|
// id: userLoginId as string,
|
|
// },
|
|
// },
|
|
// ],
|
|
},
|
|
include: {
|
|
Profile: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
imageId: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
message: "Berhasil mendapatkan data",
|
|
data: fixData,
|
|
},
|
|
{
|
|
status: 200,
|
|
}
|
|
);
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Gagal mendapatkan data",
|
|
reason: (error as Error).message,
|
|
},
|
|
{
|
|
status: 500,
|
|
}
|
|
);
|
|
}
|
|
}
|