Compare commits
4 Commits
fixed-bug/
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c227a2850 | |||
| 5bdb998d2e | |||
| b585aa3024 | |||
| a8f9d2ac0d |
@@ -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
|
|
||||||
39
CHANGELOG_COMMIT.md
Normal file
39
CHANGELOG_COMMIT.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
## Catatan Perubahan untuk Commit
|
||||||
|
|
||||||
|
### Fitur: Penambahan Pagination pada Endpoint Admin Mobile
|
||||||
|
|
||||||
|
#### Deskripsi Umum
|
||||||
|
Telah dilakukan penambahan fitur pagination pada beberapa endpoint admin mobile untuk meningkatkan kinerja dan pengalaman pengguna saat mengakses data dalam jumlah besar.
|
||||||
|
|
||||||
|
#### File yang Diubah
|
||||||
|
|
||||||
|
1. **src/app/api/mobile/admin/job/route.ts**
|
||||||
|
- Ditambahkan parameter `page` dari `searchParams`
|
||||||
|
- Diterapkan logika pagination dengan `takeData` (default 10) dan `skipData`
|
||||||
|
- Query `prisma.job.findMany` telah dimodifikasi untuk mendukung pagination
|
||||||
|
|
||||||
|
2. **src/app/api/mobile/admin/event/route.ts**
|
||||||
|
- Diperbaiki definisi variabel `page` untuk memastikan tipe data yang konsisten
|
||||||
|
- Ditambahkan default value 1 untuk parameter `page`
|
||||||
|
- Perhitungan `skipData` disesuaikan agar lebih efisien
|
||||||
|
|
||||||
|
3. **src/app/api/mobile/admin/event/[id]/participants/route.ts**
|
||||||
|
- Ditambahkan parameter `page` dari `searchParams`
|
||||||
|
- Diterapkan logika pagination dengan `takeData` (default 10) dan `skipData`
|
||||||
|
- Query `prisma.event_Peserta.findMany` telah dimodifikasi untuk mendukung pagination
|
||||||
|
|
||||||
|
#### Tujuan Perubahan
|
||||||
|
- Meningkatkan kinerja aplikasi saat mengambil data dalam jumlah besar
|
||||||
|
- Memungkinkan pengguna untuk mengakses data secara bertahap melalui halaman-halaman
|
||||||
|
- Mengurangi beban server saat mengambil data dalam jumlah besar
|
||||||
|
- Memberikan pengalaman pengguna yang lebih baik saat mengakses data admin
|
||||||
|
|
||||||
|
#### Cara Penggunaan
|
||||||
|
Untuk menggunakan fitur pagination, cukup tambahkan parameter `page` pada query string saat melakukan permintaan ke endpoint yang telah dimodifikasi. Contoh:
|
||||||
|
```
|
||||||
|
GET /api/mobile/admin/job?page=2
|
||||||
|
GET /api/mobile/admin/event?page=3
|
||||||
|
GET /api/mobile/admin/event/{id}/participants?page=1
|
||||||
|
```
|
||||||
|
|
||||||
|
Default jumlah data per halaman adalah 10 item.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
File utama: src/app/api/mobile/donation/[id]/donatur/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,9 +1,15 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Number(searchParams.get("page")) || 1;
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
|
||||||
@@ -12,6 +18,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
eventId: id,
|
eventId: id,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
eventId: true,
|
eventId: true,
|
||||||
userId: true,
|
userId: true,
|
||||||
isPresent: true,
|
isPresent: true,
|
||||||
@@ -35,6 +42,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import _ from "lodash";
|
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
import { NextResponse } from "next/server";
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
import _ from "lodash";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -11,13 +12,12 @@ async function GET(request: Request) {
|
|||||||
const fixStatus = _.startCase(category || "");
|
const fixStatus = _.startCase(category || "");
|
||||||
|
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
const page = searchParams.get("page");
|
const page = Number(searchParams.get("page")) || 1;
|
||||||
const takeData = 10;
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
const skipData = Number(page) * takeData - takeData;
|
const skipData = page * takeData - takeData;
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
console.log("[CATEGORY]", category);
|
|
||||||
// console.log("[FIX STATUS]", fixStatus);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (category === "dashboard") {
|
if (category === "dashboard") {
|
||||||
@@ -71,7 +71,6 @@ async function GET(request: Request) {
|
|||||||
typeOfEvent,
|
typeOfEvent,
|
||||||
};
|
};
|
||||||
} else if (category === "history") {
|
} else if (category === "history") {
|
||||||
console.log("[HISTORY HERE]");
|
|
||||||
|
|
||||||
const data = await prisma.event.findMany({
|
const data = await prisma.event.findMany({
|
||||||
take: page ? takeData : undefined,
|
take: page ? takeData : undefined,
|
||||||
@@ -151,21 +150,22 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
tanggal: true,
|
tanggal: true,
|
||||||
Author: {
|
tanggalSelesai: true,
|
||||||
select: {
|
Author: {
|
||||||
id: true,
|
select: {
|
||||||
username: true,
|
id: true,
|
||||||
Profile: {
|
username: true,
|
||||||
select: {
|
Profile: {
|
||||||
name: true,
|
select: {
|
||||||
},
|
name: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
fixData = data;
|
fixData = data;
|
||||||
@@ -177,7 +177,7 @@ async function GET(request: Request) {
|
|||||||
message: `Success get data event ${category}`,
|
message: `Success get data event ${category}`,
|
||||||
data: fixData,
|
data: fixData,
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 },
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`[ERROR GET DATA EVENT: ${category}]`, error);
|
console.log(`[ERROR GET DATA EVENT: ${category}]`, error);
|
||||||
@@ -187,7 +187,7 @@ async function GET(request: Request) {
|
|||||||
message: `Error get data event ${category}`,
|
message: `Error get data event ${category}`,
|
||||||
reason: (error as Error).message,
|
reason: (error as Error).message,
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|
||||||
@@ -8,6 +9,9 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
|
const page = Number(searchParams.get("page")) || 1;
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -66,6 +70,8 @@ async function GET(request: Request, { params }: { params: { name: string } }) {
|
|||||||
title: true,
|
title: true,
|
||||||
Author: true,
|
Author: true,
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
async function GET() {
|
async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
const data = await prisma.masterBank.findMany({
|
const data = await prisma.masterBank.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
updatedAt: "desc",
|
updatedAt: "desc",
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from "next/server";
|
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
@@ -11,6 +12,10 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const subBidangId = searchParams.get("subBidangId");
|
const subBidangId = searchParams.get("subBidangId");
|
||||||
|
|
||||||
|
const page = Number(searchParams.get("page")) || 1;
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
if (category === "all") {
|
if (category === "all") {
|
||||||
const bidang = await prisma.masterBidangBisnis.findUnique({
|
const bidang = await prisma.masterBidangBisnis.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@@ -45,6 +50,16 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fixData = subBidang;
|
||||||
|
} else if (category === "only-sub-bidang") {
|
||||||
|
const subBidang = await prisma.masterSubBidangBisnis.findMany({
|
||||||
|
where: {
|
||||||
|
masterBidangBisnisId: id,
|
||||||
|
},
|
||||||
|
take: takeData,
|
||||||
|
skip: skipData,
|
||||||
|
});
|
||||||
|
|
||||||
fixData = subBidang;
|
fixData = subBidang;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +86,6 @@ async function PUT(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");
|
||||||
|
|
||||||
console.log("category", category);
|
|
||||||
console.log("data", data);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (category === "bidang") {
|
if (category === "bidang") {
|
||||||
const updateData = await prisma.masterBidangBisnis.update({
|
const updateData = await prisma.masterBidangBisnis.update({
|
||||||
|
|||||||
@@ -2,15 +2,24 @@ import { NextResponse } from "next/server";
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
async function GET(request: Request) {
|
async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
|
|
||||||
const data = await prisma.masterBidangBisnis.findMany({
|
const data = await prisma.masterBidangBisnis.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: "asc",
|
createdAt: "asc",
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from "next/server";
|
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -7,10 +8,16 @@ async function GET(request: Request) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
|
console.log("SEARCH", search);
|
||||||
|
console.log("PAGE", page);
|
||||||
|
|
||||||
let fixData;
|
let fixData;
|
||||||
try {
|
try {
|
||||||
if(category === "only-user"){
|
if (category === "only-user") {
|
||||||
fixData = await prisma.user.findMany({
|
fixData = await prisma.user.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
updatedAt: "desc",
|
updatedAt: "desc",
|
||||||
@@ -22,8 +29,10 @@ async function GET(request: Request) {
|
|||||||
mode: "insensitive",
|
mode: "insensitive",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
} else if(category === "only-admin"){
|
} else if (category === "only-admin") {
|
||||||
fixData = await prisma.user.findMany({
|
fixData = await prisma.user.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
updatedAt: "desc",
|
updatedAt: "desc",
|
||||||
@@ -35,8 +44,10 @@ async function GET(request: Request) {
|
|||||||
mode: "insensitive",
|
mode: "insensitive",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
} else if (category === "all-role"){
|
} else if (category === "all-role") {
|
||||||
fixData = await prisma.user.findMany({
|
fixData = await prisma.user.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
updatedAt: "desc",
|
updatedAt: "desc",
|
||||||
@@ -48,13 +59,15 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
masterUserRoleId: "2",
|
masterUserRoleId: "2",
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
username: {
|
username: {
|
||||||
contains: search || "",
|
contains: search || "",
|
||||||
mode: "insensitive",
|
mode: "insensitive",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,13 +78,11 @@ async function GET(request: Request) {
|
|||||||
data: fixData,
|
data: fixData,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return NextResponse.json(
|
return NextResponse.json({
|
||||||
{
|
status: 500,
|
||||||
status: 500,
|
success: false,
|
||||||
success: false,
|
message: "Error get data user access",
|
||||||
message: "Error get data user access",
|
reason: (error as Error).message,
|
||||||
reason: (error as Error).message,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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