Compare commits
7 Commits
fix-server
...
v1.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
| fe457cd2d4 | |||
| 73cbf3640a | |||
| dc6fa562cc | |||
| 4fd7bb4a17 | |||
| b2305a35a6 | |||
| cbfd105134 | |||
| 3e6c94d77f |
@@ -1,8 +1,11 @@
|
||||
# ==============================
|
||||
# Database
|
||||
# ==============================
|
||||
# Tambahkan connection_limit dan pool_timeout untuk mencegah connection exhaustion
|
||||
DATABASE_URL="postgresql://user:password@localhost:5432/dbname?connection_limit=10&pool_timeout=20"
|
||||
# Connection pool settings untuk mencegah connection exhaustion:
|
||||
# - connection_limit=10: Maksimal 10 koneksi per Prisma Client instance
|
||||
# - pool_timeout=20: Timeout menunggu koneksi tersedia (detik)
|
||||
# - connect_timeout=10: Timeout untuk membuat koneksi baru (detik)
|
||||
DATABASE_URL="postgresql://user:password@localhost:5432/dbname?connection_limit=10&pool_timeout=20&connect_timeout=10"
|
||||
|
||||
# ==============================
|
||||
# Auth / Session
|
||||
|
||||
11
CHANGELOG.md
11
CHANGELOG.md
@@ -2,6 +2,17 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.7.0](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.6.9...v1.7.0) (2026-03-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Tambahkan deep link handler untuk event confirmation ([73cbf36](https://wibugit.wibudev.com/wibu/hipmi/commit/73cbf3640ac795995e15448b24408b179d2a46d2))
|
||||
|
||||
## [1.6.9](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.6.8...v1.6.9) (2026-03-06)
|
||||
|
||||
## [1.6.8](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.6.7...v1.6.8) (2026-03-05)
|
||||
|
||||
## [1.6.7](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.6.6...v1.6.7) (2026-03-04)
|
||||
|
||||
## [1.6.6](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.6.5...v1.6.6) (2026-03-03)
|
||||
|
||||
64
QWEN.md
64
QWEN.md
@@ -120,14 +120,6 @@ The team follows a structured Git workflow:
|
||||
- `style`: Styling changes
|
||||
- `perf`: Performance improvements
|
||||
|
||||
### Code Standards
|
||||
- TypeScript with strict mode enabled
|
||||
- Component header comments with file description, creator, date
|
||||
- Function comments with parameter and return value descriptions
|
||||
- Custom type interface comments
|
||||
- Error handling comments
|
||||
- Complex logic comments
|
||||
|
||||
### Commit Message Format
|
||||
```
|
||||
type: Short description
|
||||
@@ -140,6 +132,62 @@ Body:
|
||||
References: #issue-number
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```
|
||||
feat: Tambahkan fitur kalkulator
|
||||
|
||||
Deskripsi:
|
||||
- Menambahkan fungsi penambahan, pengurangan, perkalian, dan pembagian
|
||||
- Memperbolehkan pengguna untuk memasukkan dua angka dan melakukan operasi matematika
|
||||
|
||||
Fixes #12
|
||||
```
|
||||
|
||||
### Code Standards
|
||||
- TypeScript with strict mode enabled
|
||||
- Component header comments with file description, creator, date
|
||||
- Function comments with parameter and return value descriptions
|
||||
- Custom type interface comments
|
||||
- Error handling comments
|
||||
- Complex logic comments
|
||||
|
||||
### Comment Standards
|
||||
|
||||
**File Header:**
|
||||
```typescript
|
||||
/**
|
||||
* Nama File: app.ts
|
||||
* Deskripsi: Ini adalah file utama aplikasi.
|
||||
* Pembuat: John Doe
|
||||
* Tanggal: 27 Juli 2023
|
||||
*/
|
||||
```
|
||||
|
||||
**Function Comments:**
|
||||
```typescript
|
||||
/**
|
||||
* Fungsi untuk menambahkan dua angka.
|
||||
* @param {number} a - Angka pertama.
|
||||
* @param {number} b - Angka kedua.
|
||||
* @returns {number} Hasil penjumlahan a dan b.
|
||||
*/
|
||||
function addNumbers(a: number, b: number): number {
|
||||
return a + b;
|
||||
}
|
||||
```
|
||||
|
||||
**Custom Type Comments:**
|
||||
```typescript
|
||||
/**
|
||||
* Interface untuk merepresentasikan informasi pelanggan.
|
||||
*/
|
||||
interface Customer {
|
||||
id: number; // ID pelanggan
|
||||
name: string; // Nama pelanggan
|
||||
age?: number; // Umur pelanggan (opsional)
|
||||
}
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
### Main Directories
|
||||
|
||||
@@ -16,6 +16,21 @@ const nextConfig = {
|
||||
}
|
||||
return config;
|
||||
},
|
||||
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: "/.well-known/:path*",
|
||||
headers: [
|
||||
{ key: "Content-Type", value: "application/json" },
|
||||
{
|
||||
key: "Cache-Control",
|
||||
value: "no-cache, no-store, must-revalidate",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
module.exports = nextConfig;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.6.7",
|
||||
"version": "1.7.0",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
@@ -13,6 +13,6 @@ import { generate_seeder } from "./../src/app_modules/_global/fun/generate_seede
|
||||
console.error("<< error seeder", e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
// .finally(async () => {
|
||||
// await prisma.$disconnect();
|
||||
// });
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
[{
|
||||
"relation": ["delegate_permission/common.handle_all_urls"],
|
||||
"target": {
|
||||
"namespace": "android_app",
|
||||
"package_name": "com.bip.hipmimobileapp",
|
||||
"sha256_cert_fingerprints": ["CFF8431520BFAE665025B68138774A4E64AA6338D2DF6C7D900A71F0551FFD2D"]
|
||||
[
|
||||
{
|
||||
"relation": ["delegate_permission/common.handle_all_urls"],
|
||||
"target": {
|
||||
"namespace": "android_app",
|
||||
"package_name": "com.bip.hipmimobileapp",
|
||||
"sha256_cert_fingerprints": ["CFF8431520BFAE665025B68138774A4E64AA6338D2DF6C7D900A71F0551FFD2D"]
|
||||
}
|
||||
}
|
||||
}]
|
||||
]
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withRetry } from "@/lib/prisma-retry";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -16,13 +17,25 @@ export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const userId = searchParams.get("id");
|
||||
|
||||
const data = await prisma.notifikasi.count({
|
||||
where: {
|
||||
adminId: userId,
|
||||
userRoleId: "2",
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
if (!userId) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "User ID is required" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const data = await withRetry(
|
||||
() =>
|
||||
prisma.notifikasi.count({
|
||||
where: {
|
||||
adminId: userId,
|
||||
userRoleId: "2",
|
||||
isRead: false,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"countAdminNotifications"
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -33,7 +46,25 @@ export async function GET(request: Request) {
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
||||
console.error("Error get count notifikasi", error);
|
||||
|
||||
// Check if it's a database connection error
|
||||
if (
|
||||
errorMsg.includes("Prisma") ||
|
||||
errorMsg.includes("database") ||
|
||||
errorMsg.includes("connection")
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Database connection error. Please try again.",
|
||||
data: null,
|
||||
},
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
|
||||
@@ -50,7 +50,5 @@ async function DELETE(
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { withRetry } from "@/lib/prisma-retry";
|
||||
import { prisma } from "@/lib";
|
||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -9,11 +10,26 @@ export async function POST(req: Request) {
|
||||
const body = await req.json();
|
||||
const { nomor } = body;
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
nomor: nomor,
|
||||
},
|
||||
});
|
||||
if (!nomor) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Nomor telepon diperlukan",
|
||||
status: 400,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const user = await withRetry(
|
||||
() =>
|
||||
prisma.user.findUnique({
|
||||
where: {
|
||||
nomor: nomor,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"findUserByNomor"
|
||||
);
|
||||
|
||||
if (!user)
|
||||
return NextResponse.json({
|
||||
@@ -22,12 +38,17 @@ export async function POST(req: Request) {
|
||||
status: 404,
|
||||
});
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
data: {
|
||||
nomor: nomor,
|
||||
otp: codeOtp,
|
||||
},
|
||||
});
|
||||
const createOtpId = await withRetry(
|
||||
() =>
|
||||
prisma.kodeOtp.create({
|
||||
data: {
|
||||
nomor: nomor,
|
||||
otp: codeOtp,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"createOTP"
|
||||
);
|
||||
|
||||
if (!createOtpId)
|
||||
return NextResponse.json(
|
||||
@@ -59,6 +80,25 @@ export async function POST(req: Request) {
|
||||
{ status: 200 },
|
||||
);
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
||||
console.error("Mobile login error:", error);
|
||||
|
||||
// Check if it's a database connection error
|
||||
if (
|
||||
errorMsg.includes("Prisma") ||
|
||||
errorMsg.includes("database") ||
|
||||
errorMsg.includes("connection")
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Database connection error. Please try again.",
|
||||
status: 503,
|
||||
},
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
|
||||
@@ -64,7 +64,5 @@ export async function POST(req: Request) {
|
||||
},
|
||||
{ status: 500 },
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,5 @@ export async function GET(
|
||||
{ success: false, message: "Gagal mendapatkan data" },
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,11 @@ export async function GET(request: Request) {
|
||||
fixData = false;
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Success get data", data: fixData },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error get data detail event:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -41,13 +41,11 @@ export async function POST(
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success create sponsor",
|
||||
});
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error create sponsor event", error);
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Failed create sponsor" },
|
||||
@@ -100,7 +98,5 @@ export async function GET(
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ export async function GET(
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success create sponsor",
|
||||
@@ -66,7 +65,6 @@ export async function GET(
|
||||
});
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get sponsor event", error);
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
|
||||
@@ -33,7 +33,5 @@ export async function GET(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,5 @@ export async function GET(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,11 @@ export async function GET(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Berhasil mendapatkan data", data: res },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error Get Master Status Transaksi >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -28,7 +28,5 @@ async function GET() {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { withRetry } from "@/lib/prisma-retry";
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
@@ -22,28 +23,38 @@ export async function GET(
|
||||
let fixData;
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
});
|
||||
const data = await withRetry(
|
||||
() =>
|
||||
prisma.notifikasi.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"getNotifications"
|
||||
);
|
||||
|
||||
// Jika pagination digunakan, ambil juga total count untuk informasi
|
||||
let totalCount;
|
||||
let totalPages;
|
||||
if (page) {
|
||||
totalCount = await prisma.notifikasi.count({
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
});
|
||||
totalCount = await withRetry(
|
||||
() =>
|
||||
prisma.notifikasi.count({
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"countNotifications"
|
||||
);
|
||||
totalPages = Math.ceil(totalCount / takeData);
|
||||
}
|
||||
|
||||
@@ -69,8 +80,23 @@ export async function GET(
|
||||
|
||||
return NextResponse.json(response);
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
||||
console.error("Error getting notifications:", error);
|
||||
|
||||
// Check if it's a database connection error
|
||||
if (
|
||||
errorMsg.includes("Prisma") ||
|
||||
errorMsg.includes("database") ||
|
||||
errorMsg.includes("connection")
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{ error: "Database connection error. Please try again." },
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ error: errorMsg },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { withRetry } from "@/lib/prisma-retry";
|
||||
import { prisma } from "@/lib";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
@@ -9,12 +10,24 @@ export async function GET(
|
||||
console.log("User ID:", id);
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.count({
|
||||
where: {
|
||||
recipientId: id,
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
if (!id) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "User ID is required",
|
||||
});
|
||||
}
|
||||
|
||||
const data = await withRetry(
|
||||
() =>
|
||||
prisma.notifikasi.count({
|
||||
where: {
|
||||
recipientId: id,
|
||||
isRead: false,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"countUnreadNotifications"
|
||||
);
|
||||
|
||||
console.log("List Notification >>", data);
|
||||
|
||||
@@ -23,6 +36,21 @@ export async function GET(
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
||||
console.error("Error getting unread count:", error);
|
||||
|
||||
// Check if it's a database connection error
|
||||
if (
|
||||
errorMsg.includes("Prisma") ||
|
||||
errorMsg.includes("database") ||
|
||||
errorMsg.includes("connection")
|
||||
) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Database connection error. Please try again.",
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed to get unread count",
|
||||
|
||||
@@ -131,7 +131,5 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,5 @@ export async function GET(request: Request) {
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,5 @@ export async function GET(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,14 +49,11 @@ export async function GET(
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Success get data news", data: fixData },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
await prisma.$disconnect();
|
||||
backendLogger.error("Error get data news", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -36,8 +36,6 @@ export async function GET(
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Success get data document", data: fixData },
|
||||
{ status: 200 }
|
||||
|
||||
@@ -104,7 +104,5 @@ async function PUT(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,5 @@ async function POST(request: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { decrypt } from "@/app/(auth)/_lib/decrypt";
|
||||
import { withRetry } from "@/lib/prisma-retry";
|
||||
import { prisma } from "@/lib";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -43,11 +44,16 @@ export async function GET(req: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: decrypted.id,
|
||||
},
|
||||
});
|
||||
const user = await withRetry(
|
||||
() =>
|
||||
prisma.user.findUnique({
|
||||
where: {
|
||||
id: decrypted.id,
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
"validateUser"
|
||||
);
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json(
|
||||
@@ -76,25 +82,44 @@ export async function GET(req: Request) {
|
||||
data: user,
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : 'Unknown error';
|
||||
const errorStack = error instanceof Error ? error.stack : 'No stack';
|
||||
|
||||
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
||||
const errorStack = error instanceof Error ? error.stack : "No stack";
|
||||
|
||||
// Log detailed error for debugging
|
||||
console.error("❌ [USER-VALIDATE] Error:", errorMsg);
|
||||
console.error("❌ [USER-VALIDATE] Stack:", errorStack);
|
||||
console.error("❌ [USER-VALIDATE] Time:", new Date().toISOString());
|
||||
|
||||
|
||||
// Check if it's a database connection error
|
||||
if (errorMsg.includes("Prisma") || errorMsg.includes("database") || errorMsg.includes("connection")) {
|
||||
console.error("❌ [USER-VALIDATE] Database connection error detected!");
|
||||
console.error("❌ [USER-VALIDATE] DATABASE_URL exists:", !!process.env.DATABASE_URL);
|
||||
if (
|
||||
errorMsg.includes("Prisma") ||
|
||||
errorMsg.includes("database") ||
|
||||
errorMsg.includes("connection")
|
||||
) {
|
||||
console.error(
|
||||
"❌ [USER-VALIDATE] Database connection error detected!"
|
||||
);
|
||||
console.error(
|
||||
"❌ [USER-VALIDATE] DATABASE_URL exists:",
|
||||
!!process.env.DATABASE_URL
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Database connection error. Please try again.",
|
||||
error: process.env.NODE_ENV === "development" ? errorMsg : "Internal server error",
|
||||
},
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Terjadi kesalahan pada server",
|
||||
error: process.env.NODE_ENV === 'development' ? errorMsg : 'Internal server error',
|
||||
error:
|
||||
process.env.NODE_ENV === "development" ? errorMsg : "Internal server error",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
|
||||
@@ -125,7 +125,5 @@ export async function GET(request: Request) {
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
186
src/app/event/[id]/confirmation/route.ts
Normal file
186
src/app/event/[id]/confirmation/route.ts
Normal file
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* Route Handler untuk Deep Link Event Confirmation
|
||||
* File: app/event/[id]/confirmation/route.ts
|
||||
* Deskripsi: Handle GET request untuk deep link event confirmation dengan redirect ke mobile app
|
||||
* Pembuat: Assistant
|
||||
* Tanggal: 9 Maret 2026
|
||||
*/
|
||||
|
||||
import { url } from "inspector";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
/**
|
||||
* Detect platform dari User Agent string
|
||||
* @param userAgent - User Agent string dari request
|
||||
* @returns Platform type: 'ios', 'android', atau 'web'
|
||||
*/
|
||||
function detectPlatform(userAgent: string | null): "ios" | "android" | "web" {
|
||||
if (!userAgent) {
|
||||
return "web";
|
||||
}
|
||||
|
||||
const lowerUA = userAgent.toLowerCase();
|
||||
|
||||
// Detect iOS devices
|
||||
if (
|
||||
/iphone|ipad|ipod/.test(lowerUA) ||
|
||||
(lowerUA.includes("mac") && (("ontouchend" in {}) as any))
|
||||
) {
|
||||
return "ios";
|
||||
}
|
||||
|
||||
// Detect Android devices
|
||||
if (/android/.test(lowerUA)) {
|
||||
return "android";
|
||||
}
|
||||
|
||||
// Default to web
|
||||
return "web";
|
||||
}
|
||||
|
||||
/**
|
||||
* Build custom scheme URL untuk mobile app
|
||||
* @param eventId - Event ID dari URL
|
||||
* @param userId - User ID dari query parameter
|
||||
* @param platform - Platform yang terdetect
|
||||
* @returns Custom scheme URL
|
||||
*/
|
||||
function buildCustomSchemeUrl(
|
||||
eventId: string,
|
||||
userId: string | null,
|
||||
platform: "ios" | "android" | "web",
|
||||
): string {
|
||||
const baseUrl = "hipmimobile://event";
|
||||
const url = `${baseUrl}/${eventId}/confirmation${userId ? `?userId=${userId}` : ""}`;
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get base URL dari environment
|
||||
*/
|
||||
function getBaseUrl(): string {
|
||||
const env = process.env.NEXT_PUBLIC_ENV || "development";
|
||||
|
||||
if (env === "production") {
|
||||
return "https://hipmi.muku.id";
|
||||
}
|
||||
|
||||
if (env === "staging") {
|
||||
return "https://cld-dkr-hipmi-stg.wibudev.com";
|
||||
}
|
||||
|
||||
return "http://localhost:3000";
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle GET request untuk deep link
|
||||
* @param request - Next.js request object
|
||||
* @returns Redirect ke mobile app atau JSON response untuk debugging
|
||||
*/
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } },
|
||||
) {
|
||||
try {
|
||||
// Parse query parameters
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
const eventId = params.id;
|
||||
const userId = searchParams.get("userId") || null;
|
||||
const userAgent = request.headers.get("user-agent") || "";
|
||||
|
||||
// Detect platform
|
||||
const platform = detectPlatform(userAgent);
|
||||
|
||||
// Log untuk tracking
|
||||
console.log("[Deep Link] Event Confirmation Received:", {
|
||||
eventId,
|
||||
userId,
|
||||
platform,
|
||||
userAgent:
|
||||
userAgent.substring(0, 100) + (userAgent.length > 100 ? "..." : ""),
|
||||
timestamp: new Date().toISOString(),
|
||||
url: request.url,
|
||||
});
|
||||
|
||||
// Build custom scheme URL untuk redirect
|
||||
const customSchemeUrl = buildCustomSchemeUrl(eventId, userId, platform);
|
||||
|
||||
// Redirect ke mobile app untuk iOS dan Android
|
||||
if (platform === "ios" || platform === "android") {
|
||||
console.log("[Deep Link] Redirecting to mobile app:", customSchemeUrl);
|
||||
|
||||
// Redirect ke custom scheme URL
|
||||
return NextResponse.redirect(customSchemeUrl);
|
||||
}
|
||||
|
||||
console.log("[Deep Link] Environment:", process.env.NEXT_PUBLIC_ENV);
|
||||
console.log("[Deep Link] Base URL:", getBaseUrl());
|
||||
console.log("[Deep Link] Request:", {
|
||||
eventId,
|
||||
userId,
|
||||
platform,
|
||||
url: request.url,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
|
||||
// Untuk web/desktop, tampilkan JSON response untuk debugging
|
||||
const responseData = {
|
||||
success: true,
|
||||
message: "Deep link received - Web fallback",
|
||||
data: {
|
||||
eventId,
|
||||
userId,
|
||||
platform,
|
||||
userAgent,
|
||||
timestamp: new Date().toISOString(),
|
||||
url: request.url,
|
||||
customSchemeUrl,
|
||||
note: "This is a web fallback. Mobile users will be redirected to the app.",
|
||||
},
|
||||
};
|
||||
|
||||
return NextResponse.json(responseData, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "Content-Type",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[Deep Link] Error processing request:", error);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error processing deep link",
|
||||
error: error instanceof Error ? error.message : "Unknown error",
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle OPTIONS request untuk CORS preflight
|
||||
*/
|
||||
export async function OPTIONS() {
|
||||
return NextResponse.json(
|
||||
{},
|
||||
{
|
||||
status: 200,
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "Content-Type",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -669,10 +669,8 @@ const limit = pLimit(1);
|
||||
export async function generate_seeder() {
|
||||
try {
|
||||
await Promise.all(listSeederQueue.map((fn) => limit(fn)));
|
||||
await prisma.$disconnect();
|
||||
} catch (error) {
|
||||
console.error("error generate seeder", error);
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
return { status: 200, success: true };
|
||||
|
||||
@@ -37,6 +37,5 @@ export async function AdminDonasi_getOneById(id: string) {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -33,12 +33,10 @@ export async function AdminDonasi_funUpdateStatusPublish(
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Data tidak ditemukan" };
|
||||
}
|
||||
|
||||
revalidatePath(RouterAdminDonasi.table_review);
|
||||
await prisma.$disconnect();
|
||||
|
||||
return {
|
||||
data: data,
|
||||
|
||||
@@ -36,12 +36,10 @@ export default async function adminNotifikasi_funCreateToAllUser({
|
||||
},
|
||||
});
|
||||
if (!create) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return {
|
||||
status: 201,
|
||||
message: "Berhasil mengirim notifikasi",
|
||||
|
||||
@@ -25,10 +25,8 @@ export default async function adminNotifikasi_funCreateToUser({
|
||||
});
|
||||
|
||||
if (!create) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return { status: 201, message: "Berhasil mengirim notifikasi" };
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@ export async function donasi_checkStatus({ id }: { id: string }) {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
|
||||
|
||||
if (checkStatus?.donasiMaster_StatusDonasiId == "2") return true;
|
||||
return false;
|
||||
|
||||
|
||||
@@ -7,23 +7,22 @@ const sendCodeOtp = async ({
|
||||
codeOtp?: string;
|
||||
newMessage?: string;
|
||||
}) => {
|
||||
const msg = newMessage || `HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
|
||||
const enCode = encodeURIComponent(msg);
|
||||
const res = await fetch(
|
||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${enCode}`,
|
||||
{
|
||||
cache: "no-cache",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
|
||||
},
|
||||
const msg =
|
||||
newMessage ||
|
||||
`HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
|
||||
const enCode = msg;
|
||||
|
||||
const res = await fetch(`https://otp.wibudev.com/api/wa/send-text`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
|
||||
},
|
||||
);
|
||||
// const res = await fetch(
|
||||
// `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
|
||||
// \n
|
||||
// >> Kode OTP anda: ${codeOtp}.
|
||||
// `,
|
||||
// );
|
||||
body: JSON.stringify({
|
||||
number: nomor,
|
||||
text: enCode,
|
||||
}),
|
||||
});
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -1,21 +1,55 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
/**
|
||||
* Instance global Prisma client untuk connection pooling
|
||||
* Menggunakan pattern globalThis untuk mencegah multiple instance selama:
|
||||
* - Hot module replacement (HMR) di development
|
||||
* - Multiple import di seluruh aplikasi
|
||||
* - Server-side rendering di Next.js
|
||||
*/
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var prisma: PrismaClient | undefined;
|
||||
}
|
||||
|
||||
// if (!process.env.DATABASE_URL) {
|
||||
// throw new Error("DATABASE_URL is required but not found in environment variables");
|
||||
// }
|
||||
|
||||
// Konfigurasi connection pool via parameter query DATABASE_URL:
|
||||
// connection_limit=10&pool_timeout=20&connect_timeout=10
|
||||
const prisma =
|
||||
global.prisma ??
|
||||
globalThis.prisma ??
|
||||
new PrismaClient({
|
||||
log: process.env.NODE_ENV === "development" ? ["error", "warn", "query"] : ["error", "warn"],
|
||||
log:
|
||||
process.env.NODE_ENV === "development"
|
||||
? ["error", "warn"]
|
||||
: ["error"],
|
||||
datasources: {
|
||||
db: {
|
||||
url: process.env.DATABASE_URL,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Selalu assign ke global agar hanya ada 1 instance (dev: cegah hot-reload, prod: cegah multiple instances)
|
||||
global.prisma = prisma;
|
||||
// Hanya assign ke global di development untuk mencegah multiple instance saat HMR
|
||||
// Di production, ini di-skip karena tidak ada HMR
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
globalThis.prisma = prisma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler graceful shutdown untuk koneksi Prisma
|
||||
* Panggil ini HANYA saat terminasi process (SIGINT/SIGTERM)
|
||||
* JANGAN panggil $disconnect() setelah query individual
|
||||
*/
|
||||
async function gracefulShutdown(): Promise<void> {
|
||||
console.log("[Prisma] Menutup koneksi database...");
|
||||
await prisma.$disconnect();
|
||||
console.log("[Prisma] Semua koneksi ditutup");
|
||||
}
|
||||
|
||||
// Register shutdown handlers (hanya di environment Node.js)
|
||||
if (typeof process !== "undefined") {
|
||||
process.on("SIGINT", gracefulShutdown);
|
||||
process.on("SIGTERM", gracefulShutdown);
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
export { prisma };
|
||||
|
||||
@@ -49,6 +49,7 @@ const CONFIG: MiddlewareConfig = {
|
||||
"/auth/api/login",
|
||||
"/waiting-room",
|
||||
"/zCoba/*",
|
||||
"/event/*/confirmation",
|
||||
"/aset/global/main_background.png",
|
||||
"/aset/logo/logo-hipmi.png",
|
||||
"/aset/logo/hiconnect.png",
|
||||
|
||||
Reference in New Issue
Block a user