Merge pull request 'Fix Admin API Mobile' (#58) from mobile-api/18-feb-26 into staging
Reviewed-on: #58
This commit is contained in:
@@ -1,63 +0,0 @@
|
|||||||
# Changelog for Branch: fixed-bug/12-feb-26
|
|
||||||
|
|
||||||
## Summary
|
|
||||||
This branch contains several bug fixes and performance improvements, primarily focusing on:
|
|
||||||
- Database connection management
|
|
||||||
- MQTT client stability
|
|
||||||
- Logging optimization
|
|
||||||
- API enhancements
|
|
||||||
|
|
||||||
## Detailed Changes
|
|
||||||
|
|
||||||
### Fixed Issues
|
|
||||||
1. **Database Connection Management**
|
|
||||||
- Removed `prisma.$disconnect()` from user-validate API route to prevent connection pool exhaustion
|
|
||||||
- Added proper connection handling in global Prisma setup
|
|
||||||
- Reduced logging verbosity in production environments
|
|
||||||
|
|
||||||
2. **MQTT Client Improvements**
|
|
||||||
- Enhanced MQTT client initialization with proper error handling
|
|
||||||
- Added reconnection logic with configurable intervals
|
|
||||||
- Implemented cleanup functions to prevent memory leaks
|
|
||||||
- Added separate initialization logic for server and client-side code
|
|
||||||
|
|
||||||
3. **Logging Optimization**
|
|
||||||
- Removed excessive logging in middleware that was causing high CPU usage
|
|
||||||
- Configured appropriate log levels for development and production
|
|
||||||
|
|
||||||
4. **Component Stability**
|
|
||||||
- Added safety checks in text editor component to prevent MQTT operations on the server side
|
|
||||||
- Improved MQTT publishing logic with client availability checks
|
|
||||||
|
|
||||||
### New Files
|
|
||||||
- `src/lib/prismaUtils.ts` - Utility functions for safe database operations
|
|
||||||
|
|
||||||
### Modified Files
|
|
||||||
1. `src/app/api/user-validate/route.ts`
|
|
||||||
- Removed problematic `prisma.$disconnect()` call
|
|
||||||
|
|
||||||
2. `src/lib/prisma.ts`
|
|
||||||
- Configured different logging levels for dev/prod
|
|
||||||
- Removed process listeners that were causing disconnections
|
|
||||||
- Exported prisma instance separately
|
|
||||||
|
|
||||||
3. `src/middleware.tsx`
|
|
||||||
- Removed excessive logging statements
|
|
||||||
|
|
||||||
4. `src/util/mqtt_client.ts`
|
|
||||||
- Enhanced initialization with error handling
|
|
||||||
- Added reconnection and timeout configurations
|
|
||||||
|
|
||||||
5. `src/util/mqtt_loader.tsx`
|
|
||||||
- Added proper cleanup functions
|
|
||||||
- Improved connection handling
|
|
||||||
|
|
||||||
6. `src/app_modules/_global/component/new/comp_V3_text_editor_stiker.tsx`
|
|
||||||
- Added MQTT client availability checks
|
|
||||||
- Prevented server-side MQTT operations
|
|
||||||
|
|
||||||
### Performance Improvements
|
|
||||||
- Reduced database connection overhead
|
|
||||||
- Optimized MQTT connection handling
|
|
||||||
- Eliminated unnecessary logging in production
|
|
||||||
- Better memory management with proper cleanup functions
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
File utama: src/app/api/mobile/admin/event/[id]/participants/route.ts
|
File utama: src/app/api/mobile/admin/donation/[id]/donatur/route.ts
|
||||||
|
|
||||||
Terapkan pagination pada file "File utama" pada method GET
|
Terapkan pagination pada file "File utama" pada method GET
|
||||||
Analisa juga file "File utama", jika belum memiliki page dari seachParams maka terapkan. Juga pastikan take dan skip sudah sesuai dengan pagination. Buat default nya menjadi 10 untuk take data
|
Analisa juga file "File utama", jika belum memiliki page dari seachParams maka terapkan. Juga pastikan take dan skip sudah sesuai dengan pagination. Buat default nya menjadi 10 untuk take data
|
||||||
|
|||||||
2
QWEN.md
2
QWEN.md
@@ -198,4 +198,4 @@ References: #issue-number
|
|||||||
### Data Protection
|
### Data Protection
|
||||||
- Encrypted tokens
|
- Encrypted tokens
|
||||||
- Secure API routes
|
- Secure API routes
|
||||||
- Proper CORS configuration
|
- Proper CORS configuration
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
NotificationMobileTitleType,
|
NotificationMobileTitleType,
|
||||||
} from "../../../../../../../../types/type-mobile-notification";
|
} from "../../../../../../../../types/type-mobile-notification";
|
||||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { POST, GET };
|
export { POST, GET };
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const page = searchParams.get("page");
|
const page = searchParams.get("page");
|
||||||
const takeData = 10;
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
const skipData = Number(page) * takeData - takeData;
|
const skipData = Number(page) * takeData - takeData;
|
||||||
|
|
||||||
console.log("[CATEGORY]", category);
|
console.log("[CATEGORY]", category);
|
||||||
@@ -174,6 +175,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
id: true,
|
id: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
nominalCair: true,
|
nominalCair: true,
|
||||||
|
title: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (category === "get-one") {
|
} else if (category === "get-one") {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ async function GET(req: Request, { params }: { params: { id: string } }) {
|
|||||||
const { searchParams } = new URL(req.url);
|
const { searchParams } = new URL(req.url);
|
||||||
const page = searchParams.get("page");
|
const page = searchParams.get("page");
|
||||||
const status = searchParams.get("status");
|
const status = searchParams.get("status");
|
||||||
const takeData = 10;
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
const skipData = Number(page) * takeData - takeData;
|
const skipData = Number(page) * takeData - takeData;
|
||||||
const fixStatus = _.startCase(status || "");
|
const fixStatus = _.startCase(status || "");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -9,11 +10,10 @@ async function GET(request: Request) {
|
|||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const page = searchParams.get("page");
|
const page = searchParams.get("page");
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
const takeData = 10;
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
const skipData = Number(page) * takeData - takeData;
|
const skipData = Number(page) * takeData - takeData;
|
||||||
console.log("[CATEGORY]", category);
|
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (category === "dashboard") {
|
if (category === "dashboard") {
|
||||||
const publish = await prisma.donasi.count({
|
const publish = await prisma.donasi.count({
|
||||||
@@ -48,7 +48,7 @@ async function GET(request: Request) {
|
|||||||
where: {
|
where: {
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const categoryDonation = countCategoryDonation.length;
|
const categoryDonation = countCategoryDonation.length;
|
||||||
@@ -68,7 +68,6 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[STATUS]", checkStatus);
|
|
||||||
|
|
||||||
if (!checkStatus) {
|
if (!checkStatus) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -77,7 +76,7 @@ async function GET(request: Request) {
|
|||||||
message: "Failed to get data donation",
|
message: "Failed to get data donation",
|
||||||
reason: "Status not found",
|
reason: "Status not found",
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +99,12 @@ async function GET(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
|
target: true,
|
||||||
|
DonasiMaster_Durasi: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
Author: {
|
Author: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -109,7 +114,6 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[LIST]", fixData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -118,7 +122,7 @@ async function GET(request: Request) {
|
|||||||
message: `Success get data donation ${category}`,
|
message: `Success get data donation ${category}`,
|
||||||
data: fixData,
|
data: fixData,
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 },
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error get data donation:", error);
|
console.error("Error get data donation:", error);
|
||||||
@@ -128,7 +132,7 @@ async function GET(request: Request) {
|
|||||||
message: "Failed to get data donation",
|
message: "Failed to get data donation",
|
||||||
reason: (error as Error).message,
|
reason: (error as Error).message,
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
async function GET(request: Request) {
|
async function GET(request: NextRequest) {
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
// const category = searchParams.get("category");
|
// const category = searchParams.get("category");
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
@@ -13,6 +17,8 @@ async function GET(request: Request) {
|
|||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: "asc",
|
createdAt: "asc",
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
// if (category === "category") {
|
// if (category === "category") {
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
async function GET(request: Request) {
|
async function GET(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
|
const searchParams = request.nextUrl.searchParams;
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
const data = await prisma.eventMaster_TipeAcara.findMany({
|
const data = await prisma.eventMaster_TipeAcara.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
updatedAt: "desc",
|
updatedAt: "desc",
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import _ from "lodash";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ async function GET(request: Request) {
|
|||||||
|
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
const page = searchParams.get("page");
|
const page = searchParams.get("page");
|
||||||
const takeData = 10;
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
const skipData = Number(page) * takeData - takeData;
|
const skipData = Number(page) * takeData - takeData;
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user