Compare commits
12 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| b585aa3024 | |||
| a8f9d2ac0d | |||
| d43f3762a3 | |||
| e89886e1db | |||
| 934d6a3ef1 | |||
| a7694bd7d5 | |||
| 3b0ea3d847 | |||
| 097758a431 | |||
| 6f5849aa29 | |||
| 6aceb212e4 | |||
| 42803f9b92 | |||
| 2a857f54e7 |
@@ -2,6 +2,8 @@
|
||||
|
||||
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.5.40](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.39...v1.5.40) (2026-02-06)
|
||||
|
||||
## [1.5.39](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.38...v1.5.39) (2026-01-30)
|
||||
|
||||
## [1.5.38](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.37...v1.5.38) (2026-01-27)
|
||||
|
||||
63
CHANGELOG_BRANCH.md
Normal file
63
CHANGELOG_BRANCH.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# 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
|
||||
31
PROMPT-AI.md
31
PROMPT-AI.md
@@ -1,5 +1,5 @@
|
||||
|
||||
File utama: src/app/api/mobile/notification/[id]/route.ts
|
||||
File utama: src/app/api/mobile/admin/master/business-field/route.ts
|
||||
|
||||
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
|
||||
@@ -14,3 +14,32 @@ take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
|
||||
Gunakan bahasa indonesia pada cli agar saya mudah membacanya.
|
||||
|
||||
<!-- Additinal prompt -->
|
||||
File refrensi: src/app/api/mobile/event/[id]/[status]/route.ts
|
||||
Anda bisa menggunakan refrensi dari "File refrensi" jika butuh pemahaman dengan tipe fitur yang sama
|
||||
|
||||
|
||||
<!-- Auto input promt -->
|
||||
End-point: src/app/api/mobile/donation/route.ts
|
||||
|
||||
Buatkan auto input untuk method POST dengan data yang dibutuhkan sesuai dengan struktur data yang ada di file tersebut, tidak perlu "temporary" cukup data "permanent" dengan ketentuan sebagai berikut:
|
||||
- authorId: string ( cmha6wb9w0001cfndwl9fcse6 )
|
||||
- title: string
|
||||
- target: number
|
||||
- donasiMaster_DurasiId: number ( 3 )
|
||||
- donasiMaster_KategoriId: number ( 3 )
|
||||
- namaBank: string
|
||||
- rekening: string
|
||||
- imageId: number ( cm60j9q3m000xc9dc584v8rh8 )
|
||||
|
||||
Untuk sisa nya anda bisa bebas mengisi data tersebut.
|
||||
|
||||
<!-- COMMIT & PUSH -->
|
||||
Branch: mobile-api/10-feb-26
|
||||
Jalankan perintah ini: git checkout -b "Branch"
|
||||
Setelah itu jalankan perintah ini: git add .
|
||||
Setelah itu jalankan perintah ini: git commit -m "
|
||||
<Berikan semua catatan perubahan pada branch ini, tampilan pada saya dan pastikan dalam bahasa indonesia. Saya akan cek baru saya akan berikan perintah push>
|
||||
"
|
||||
Setelah itu jalankan perintah ini: git push origin "Branch"
|
||||
2
QWEN.md
2
QWEN.md
@@ -2,7 +2,7 @@
|
||||
|
||||
## Project Overview
|
||||
|
||||
HIPMI (Himpunan Pengusaha Muda Indonesia) is a comprehensive Next.js-based web application built for the Indonesian Young Entrepreneurs Association. The project is a sophisticated platform that provides multiple business functionalities including investment management, donations, events, job listings, forums, voting systems, and collaborative projects.
|
||||
HIPMI (Himpunan Pengusaha Muya Indonesia) is a comprehensive Next.js-based web application built for the Indonesian Young Entrepreneurs Association. The project is a sophisticated platform that provides multiple business functionalities including investment management, donations, events, job listings, forums, voting systems, and collaborative projects.
|
||||
|
||||
### Key Technologies
|
||||
- **Framework**: Next.js 13+ (with App Router)
|
||||
|
||||
19
bun.lock
19
bun.lock
@@ -39,6 +39,7 @@
|
||||
"@types/react-dom": "18.2.7",
|
||||
"@types/uuid": "^9.0.4",
|
||||
"autoprefixer": "10.4.14",
|
||||
"axios": "^1.13.5",
|
||||
"bufferutil": "^4.0.8",
|
||||
"bun": "^1.1.38",
|
||||
"caniuse-lite": "^1.0.30001757",
|
||||
@@ -1324,7 +1325,7 @@
|
||||
|
||||
"axe-core": ["axe-core@4.10.2", "", {}, "sha512-RE3mdQ7P3FRSe7eqCWoeQ/Z9QXrtniSjp1wUjt5nRC3WIpz5rSCve6o3fsZ2aCpJtrZjSZgjwXAoTO5k4tEI0w=="],
|
||||
|
||||
"axios": ["axios@0.26.1", "", { "dependencies": { "follow-redirects": "^1.14.8" } }, "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA=="],
|
||||
"axios": ["axios@1.13.5", "", { "dependencies": { "follow-redirects": "^1.15.11", "form-data": "^4.0.5", "proxy-from-env": "^1.1.0" } }, "sha512-cz4ur7Vb0xS4/KUN0tPWe44eqxrIu31me+fbang3ijiNscE129POzipJJA6zniq2C/Z6sJCjMimjS8Lc/GAs8Q=="],
|
||||
|
||||
"axobject-query": ["axobject-query@4.1.0", "", {}, "sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ=="],
|
||||
|
||||
@@ -1882,7 +1883,7 @@
|
||||
|
||||
"fn.name": ["fn.name@1.1.0", "", {}, "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw=="],
|
||||
|
||||
"follow-redirects": ["follow-redirects@1.15.9", "", {}, "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ=="],
|
||||
"follow-redirects": ["follow-redirects@1.15.11", "", {}, "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ=="],
|
||||
|
||||
"fontfaceobserver": ["fontfaceobserver@2.3.0", "", {}, "sha512-6FPvD/IVyT4ZlNe7Wcn5Fb/4ChigpucKYSvD6a+0iMoLn2inpo711eyIcKjmDtE5XNcgAkSH9uN/nfAeZzHEfg=="],
|
||||
|
||||
@@ -1892,7 +1893,7 @@
|
||||
|
||||
"foreground-child": ["foreground-child@3.3.1", "", { "dependencies": { "cross-spawn": "^7.0.6", "signal-exit": "^4.0.1" } }, "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw=="],
|
||||
|
||||
"form-data": ["form-data@4.0.2", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "mime-types": "^2.1.12" } }, "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w=="],
|
||||
"form-data": ["form-data@4.0.5", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w=="],
|
||||
|
||||
"form-data-encoder": ["form-data-encoder@1.7.2", "", {}, "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A=="],
|
||||
|
||||
@@ -3618,6 +3619,8 @@
|
||||
|
||||
"@types/jsonwebtoken/@types/node": ["@types/node@22.19.1", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-LCCV0HdSZZZb34qifBsyWlUmok6W7ouER+oQIGBScS8EsZsQbrtFTUrDX4hOl+CS6p7cnNC4td+qrSVGSCTUfQ=="],
|
||||
|
||||
"@types/node-fetch/form-data": ["form-data@4.0.2", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "mime-types": "^2.1.12" } }, "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w=="],
|
||||
|
||||
"@types/request/@types/node": ["@types/node@22.19.1", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-LCCV0HdSZZZb34qifBsyWlUmok6W7ouER+oQIGBScS8EsZsQbrtFTUrDX4hOl+CS6p7cnNC4td+qrSVGSCTUfQ=="],
|
||||
|
||||
"@types/request/form-data": ["form-data@2.5.5", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.35", "safe-buffer": "^5.2.1" } }, "sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A=="],
|
||||
@@ -3630,6 +3633,8 @@
|
||||
|
||||
"ast-types/tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
|
||||
|
||||
"autocannon/form-data": ["form-data@4.0.2", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "mime-types": "^2.1.12" } }, "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w=="],
|
||||
|
||||
"autoprefixer/caniuse-lite": ["caniuse-lite@1.0.30001701", "", {}, "sha512-faRs/AW3jA9nTwmJBSO1PQ6L/EOgsB5HMQQq4iCu5zhPgVVgO/pZRHlmatwijZKetFw8/Pr4q6dEN8sJuq8qTw=="],
|
||||
|
||||
"babel-plugin-polyfill-corejs2/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
||||
@@ -3810,6 +3815,8 @@
|
||||
|
||||
"metro-file-map/debug": ["debug@2.6.9", "", { "dependencies": { "ms": "2.0.0" } }, "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA=="],
|
||||
|
||||
"midtrans-client/axios": ["axios@0.26.1", "", { "dependencies": { "follow-redirects": "^1.14.8" } }, "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA=="],
|
||||
|
||||
"minipass-flush/minipass": ["minipass@3.3.6", "", { "dependencies": { "yallist": "^4.0.0" } }, "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw=="],
|
||||
|
||||
"minipass-pipeline/minipass": ["minipass@3.3.6", "", { "dependencies": { "yallist": "^4.0.0" } }, "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw=="],
|
||||
@@ -4190,6 +4197,12 @@
|
||||
|
||||
"metro/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="],
|
||||
|
||||
"midtrans-client/axios/follow-redirects": ["follow-redirects@1.15.9", "", {}, "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ=="],
|
||||
|
||||
"next-dev/axios/follow-redirects": ["follow-redirects@1.15.9", "", {}, "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ=="],
|
||||
|
||||
"next-dev/axios/form-data": ["form-data@4.0.2", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "mime-types": "^2.1.12" } }, "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w=="],
|
||||
|
||||
"next-dev/react-dom/scheduler": ["scheduler@0.23.2", "", { "dependencies": { "loose-envify": "^1.1.0" } }, "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ=="],
|
||||
|
||||
"next-scroll-loader/react-dom/scheduler": ["scheduler@0.23.2", "", { "dependencies": { "loose-envify": "^1.1.0" } }, "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ=="],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.39",
|
||||
"version": "1.5.40",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
@@ -50,6 +50,7 @@
|
||||
"@types/react-dom": "18.2.7",
|
||||
"@types/uuid": "^9.0.4",
|
||||
"autoprefixer": "10.4.14",
|
||||
"axios": "^1.13.5",
|
||||
"bufferutil": "^4.0.8",
|
||||
"bun": "^1.1.38",
|
||||
"caniuse-lite": "^1.0.30001757",
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
async function GET() {
|
||||
async function GET(request: Request) {
|
||||
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({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -11,6 +12,10 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const category = searchParams.get("category");
|
||||
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") {
|
||||
const bidang = await prisma.masterBidangBisnis.findUnique({
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -71,9 +86,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
console.log("category", category);
|
||||
console.log("data", data);
|
||||
|
||||
try {
|
||||
if (category === "bidang") {
|
||||
const updateData = await prisma.masterBidangBisnis.update({
|
||||
|
||||
@@ -2,15 +2,24 @@ import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
async function GET(request: Request) {
|
||||
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({
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export { GET };
|
||||
|
||||
@@ -7,10 +8,16 @@ async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
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;
|
||||
try {
|
||||
if(category === "only-user"){
|
||||
if (category === "only-user") {
|
||||
fixData = await prisma.user.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
@@ -22,8 +29,10 @@ async function GET(request: Request) {
|
||||
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({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
@@ -35,8 +44,10 @@ async function GET(request: Request) {
|
||||
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({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
@@ -48,13 +59,15 @@ async function GET(request: Request) {
|
||||
},
|
||||
{
|
||||
masterUserRoleId: "2",
|
||||
}
|
||||
},
|
||||
],
|
||||
username: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,13 +78,11 @@ async function GET(request: Request) {
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
status: 500,
|
||||
success: false,
|
||||
message: "Error get data user access",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
);
|
||||
return NextResponse.json({
|
||||
status: 500,
|
||||
success: false,
|
||||
message: "Error get data user access",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,42 @@ import { prisma } from "@/lib";
|
||||
export { POST, GET };
|
||||
|
||||
async function POST(request: NextRequest) {
|
||||
const { data } = await request.json();
|
||||
try {
|
||||
// Parse the request body - can accept either nested under 'data' or directly
|
||||
const requestBody = await request.json();
|
||||
|
||||
// Check if the data is nested under 'data' property (as described in the issue)
|
||||
// or if it's directly in the request body (more common pattern)
|
||||
const payload = requestBody.data ? requestBody.data : requestBody;
|
||||
|
||||
const { userId, platform, deviceId, model, appVersion, fcmToken } = payload;
|
||||
|
||||
const { userId, platform, deviceId, model, appVersion, fcmToken } = data;
|
||||
|
||||
// Validate required fields
|
||||
if (!fcmToken) {
|
||||
return NextResponse.json({ error: "Missing Token" }, { status: 400 });
|
||||
return NextResponse.json(
|
||||
{ error: "Missing FCM token", field: "fcmToken" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing user ID", field: "userId" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Verify that the user exists before creating/updating the device token
|
||||
const userExists = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { id: true }
|
||||
});
|
||||
|
||||
if (!userExists) {
|
||||
return NextResponse.json(
|
||||
{ error: "User not found", field: "userId" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const existing = await prisma.tokenUserDevice.findFirst({
|
||||
@@ -23,7 +52,6 @@ async function POST(request: NextRequest) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
console.log("✅ EX", existing);
|
||||
|
||||
let deviceToken;
|
||||
@@ -31,7 +59,7 @@ async function POST(request: NextRequest) {
|
||||
if (existing) {
|
||||
deviceToken = await prisma.tokenUserDevice.update({
|
||||
where: {
|
||||
id: existing?.id,
|
||||
id: existing.id,
|
||||
},
|
||||
data: {
|
||||
platform,
|
||||
@@ -43,7 +71,7 @@ async function POST(request: NextRequest) {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Buat baru jika belum ada
|
||||
// Create new device token record
|
||||
deviceToken = await prisma.tokenUserDevice.create({
|
||||
data: {
|
||||
token: fcmToken,
|
||||
@@ -58,9 +86,16 @@ async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, data: deviceToken });
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error("Error registering device token:", error);
|
||||
|
||||
// Return more informative error response
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{
|
||||
error: "Internal server error",
|
||||
message: error.message || "An unexpected error occurred",
|
||||
field: "server"
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -10,8 +11,14 @@ async function GET(
|
||||
) {
|
||||
const { id, status } = params;
|
||||
const fixStatus = _.startCase(status);
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let fixData;
|
||||
let meta = null;
|
||||
|
||||
try {
|
||||
const checkStatus = await prisma.donasiMaster_StatusDonasi.findFirst({
|
||||
where: {
|
||||
@@ -50,18 +57,38 @@ async function GET(
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
const totalData = await prisma.donasi.count({
|
||||
where: {
|
||||
authorId: id,
|
||||
donasiMaster_StatusDonasiId: checkStatus.id,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(totalData / takeData);
|
||||
|
||||
fixData = res.map((v: any) => ({
|
||||
..._.omit(v, ["DonasiMaster_Durasi"]),
|
||||
nameDonasiDurasi: v.DonasiMaster_Durasi.name,
|
||||
}));
|
||||
|
||||
meta = {
|
||||
currentPage: page,
|
||||
totalData: totalData,
|
||||
totalPage: totalPages,
|
||||
dataPerPage: takeData,
|
||||
};
|
||||
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: fixData,
|
||||
...(meta && { meta }),
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET };
|
||||
|
||||
@@ -7,7 +8,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = 5;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -9,11 +10,12 @@ export async function GET(
|
||||
let fixData;
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = 10;
|
||||
const page = Number(searchParams.get("page")) || 1; // Default page 1 jika tidak ada atau invalid
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
fixData = await prisma.donasi_Invoice.findMany({
|
||||
// Query data dengan pagination
|
||||
const data = await prisma.donasi_Invoice.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
@@ -59,10 +61,31 @@ export async function GET(
|
||||
},
|
||||
});
|
||||
|
||||
// Hitung total data untuk pagination
|
||||
const totalCount = await prisma.donasi_Invoice.count({
|
||||
where: {
|
||||
donasiId: id,
|
||||
DonasiMaster_StatusInvoice: {
|
||||
name: "Berhasil",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Hitung total halaman
|
||||
const totalPages = Math.ceil(totalCount / takeData);
|
||||
|
||||
fixData = data;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Data berhasil diambil",
|
||||
data: fixData,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages: totalPages,
|
||||
totalData: totalCount,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { funFindDonaturList } from "@/lib/mobile/donation/find-donatur-list";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET, PUT, DELETE };
|
||||
|
||||
@@ -94,11 +95,16 @@ async function GET(
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const page = Number(searchParams.get("page")) || 1; // Default page 1 jika tidak ada
|
||||
const takeData = PAGINATION_DEFAULT_TAKE; // Default 10 data per halaman
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let fixData;
|
||||
let totalCount = 0; // Untuk menghitung total data
|
||||
|
||||
try {
|
||||
if (category === "get-all") {
|
||||
fixData = await prisma.donasi_Kabar.findMany({
|
||||
const data = await prisma.donasi_Kabar.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
@@ -106,6 +112,8 @@ async function GET(
|
||||
donasiId: id,
|
||||
active: true,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
@@ -113,6 +121,17 @@ async function GET(
|
||||
createdAt: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Hitung total data untuk pagination
|
||||
totalCount = await prisma.donasi_Kabar.count({
|
||||
where: {
|
||||
donasiId: id,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
|
||||
} else if (category === "get-one") {
|
||||
const data = await prisma.donasi_Kabar.findUnique({
|
||||
where: {
|
||||
@@ -135,11 +154,24 @@ async function GET(
|
||||
};
|
||||
}
|
||||
|
||||
// Hitung total halaman jika kategori adalah get-all
|
||||
let pagination = undefined;
|
||||
if (category === "get-all") {
|
||||
const totalPages = Math.ceil(totalCount / takeData);
|
||||
pagination = {
|
||||
currentPage: page,
|
||||
totalPages: totalPages,
|
||||
totalData: totalCount,
|
||||
dataPerPage: takeData,
|
||||
};
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
success: true,
|
||||
message: "Berhasil mengambil kabar",
|
||||
data: fixData,
|
||||
pagination: pagination,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[ERROR GET NEWS]", error);
|
||||
|
||||
@@ -4,6 +4,7 @@ import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
@@ -125,7 +126,12 @@ async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const authorId = searchParams.get("authorId");
|
||||
const page = Number(searchParams.get("page")) || 1; // Default page 1 jika tidak ada
|
||||
const takeData = PAGINATION_DEFAULT_TAKE; // Default 10 data per halaman
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let fixData;
|
||||
let totalCount = 0; // Untuk menghitung total data
|
||||
|
||||
try {
|
||||
if (category === "beranda") {
|
||||
@@ -137,6 +143,8 @@ async function GET(request: Request) {
|
||||
donasiMaster_StatusDonasiId: "1",
|
||||
active: true,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
imageId: true,
|
||||
@@ -152,6 +160,14 @@ async function GET(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
// Hitung total data untuk pagination
|
||||
totalCount = await prisma.donasi.count({
|
||||
where: {
|
||||
donasiMaster_StatusDonasiId: "1",
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data.map((v: any) => ({
|
||||
..._.omit(v, ["DonasiMaster_Durasi"]),
|
||||
durasiDonasi: v.DonasiMaster_Durasi.name,
|
||||
@@ -164,6 +180,8 @@ async function GET(request: Request) {
|
||||
where: {
|
||||
authorId: authorId,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
nominal: true,
|
||||
@@ -190,6 +208,13 @@ async function GET(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
// Hitung total data untuk pagination
|
||||
totalCount = await prisma.donasi_Invoice.count({
|
||||
where: {
|
||||
authorId: authorId,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data.map((v: any) => ({
|
||||
..._.omit(v, ["DonasiMaster_StatusInvoice", "Donasi"]),
|
||||
statusInvoice: v.DonasiMaster_StatusInvoice.name,
|
||||
@@ -202,8 +227,21 @@ async function GET(request: Request) {
|
||||
}));
|
||||
}
|
||||
|
||||
// Hitung total halaman
|
||||
const totalPages = Math.ceil(totalCount / takeData);
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Data berhasil diambil", data: fixData },
|
||||
{
|
||||
success: true,
|
||||
message: "Data berhasil diambil",
|
||||
data: fixData,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages: totalPages,
|
||||
totalData: totalCount,
|
||||
dataPerPage: takeData,
|
||||
}
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -12,6 +13,11 @@ async function GET(
|
||||
const { id, status } = params;
|
||||
const fixStatusName = _.startCase(status);
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
@@ -37,13 +43,35 @@ async function GET(
|
||||
},
|
||||
authorId: true,
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
// Get total count for pagination info
|
||||
const totalCount = await prisma.event.count({
|
||||
where: {
|
||||
active: true,
|
||||
authorId: id,
|
||||
isArsip: false,
|
||||
EventMaster_Status: {
|
||||
name: fixStatusName,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(totalCount / takeData);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get event",
|
||||
data: data,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages: totalPages,
|
||||
totalData: totalCount,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
@@ -47,7 +48,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
message: "Success join event",
|
||||
data: createJoin,
|
||||
},
|
||||
{ status: 200 }
|
||||
{ status: 200 },
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
@@ -56,7 +57,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
message: "Error join event",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,12 +65,17 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.event_Peserta.findMany({
|
||||
where: {
|
||||
eventId: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
eventId: true,
|
||||
userId: true,
|
||||
isPresent: true,
|
||||
@@ -87,6 +93,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
},
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
@@ -94,8 +102,14 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
success: true,
|
||||
message: "Success get participants",
|
||||
data: data,
|
||||
meta: {
|
||||
page,
|
||||
take: takeData,
|
||||
total: await prisma.event_Peserta.count({ where: { eventId: id } }),
|
||||
totalPages: Math.ceil(await prisma.event_Peserta.count({ where: { eventId: id } }) / takeData),
|
||||
},
|
||||
},
|
||||
{ status: 200 }
|
||||
{ status: 200 },
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
@@ -104,7 +118,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
message: "Error get participants",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
@@ -76,11 +77,15 @@ async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const userId = searchParams.get("userId");
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
console.log("[CAT]", category);
|
||||
console.log("[USER]", userId);
|
||||
|
||||
let fixData;
|
||||
let totalCount = 0;
|
||||
|
||||
if (category === "beranda") {
|
||||
const allData = await prisma.event.findMany({
|
||||
@@ -108,84 +113,96 @@ async function GET(request: Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// const takeData = 10;
|
||||
// const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
// take: takeData,
|
||||
// skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
tanggal: "asc",
|
||||
const [data, count] = await Promise.all([
|
||||
prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: [
|
||||
{
|
||||
tanggal: "asc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: false,
|
||||
},
|
||||
],
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
tanggal: true,
|
||||
tanggalSelesai: true,
|
||||
EventMaster_Status: {
|
||||
select: {
|
||||
name: true,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
tanggal: true,
|
||||
tanggalSelesai: true,
|
||||
EventMaster_Status: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
authorId: true,
|
||||
Author: {
|
||||
include: {
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
authorId: true,
|
||||
Author: {
|
||||
include: {
|
||||
Profile: true,
|
||||
},
|
||||
}),
|
||||
prisma.event.count({
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
]);
|
||||
|
||||
fixData = data;
|
||||
totalCount = count;
|
||||
} else if (category === "contribution") {
|
||||
const data = await prisma.event_Peserta.findMany({
|
||||
where: {
|
||||
userId: userId,
|
||||
},
|
||||
select: {
|
||||
eventId: true,
|
||||
userId: true,
|
||||
Event: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
const [data, count] = await Promise.all([
|
||||
prisma.event_Peserta.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
where: {
|
||||
userId: userId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
eventId: true,
|
||||
userId: true,
|
||||
Event: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Event_Peserta: {
|
||||
take: 4,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
User: {
|
||||
select: {
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
Event_Peserta: {
|
||||
take: 4,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
User: {
|
||||
select: {
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -194,86 +211,109 @@ async function GET(request: Request) {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// User: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// username: true,
|
||||
// Profile: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// name: true,
|
||||
// imageId: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
},
|
||||
});
|
||||
}),
|
||||
prisma.event_Peserta.count({
|
||||
where: {
|
||||
userId: userId,
|
||||
},
|
||||
})
|
||||
]);
|
||||
|
||||
fixData = data;
|
||||
totalCount = count;
|
||||
} else if (category === "all-history") {
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
tanggal: "desc",
|
||||
},
|
||||
where: {
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
deskripsi: true,
|
||||
active: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
const [data, count] = await Promise.all([
|
||||
prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
tanggal: "desc",
|
||||
},
|
||||
where: {
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
deskripsi: true,
|
||||
active: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
prisma.event.count({
|
||||
where: {
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: true,
|
||||
},
|
||||
})
|
||||
]);
|
||||
|
||||
fixData = data;
|
||||
totalCount = count;
|
||||
} else if (category === "my-history") {
|
||||
const data = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
tanggal: "desc",
|
||||
},
|
||||
where: {
|
||||
authorId: userId,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
deskripsi: true,
|
||||
active: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
const [data, count] = await Promise.all([
|
||||
prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
tanggal: "desc",
|
||||
},
|
||||
where: {
|
||||
authorId: userId,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
deskripsi: true,
|
||||
active: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
prisma.event.count({
|
||||
where: {
|
||||
authorId: userId,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: true,
|
||||
},
|
||||
})
|
||||
]);
|
||||
|
||||
fixData = data;
|
||||
totalCount = count;
|
||||
}
|
||||
|
||||
const totalPages = Math.ceil(totalCount / takeData);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get event",
|
||||
data: fixData,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages: totalPages,
|
||||
totalData: totalCount,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -9,6 +10,10 @@ async function GET(
|
||||
{ params }: { params: { id: string; status: string } }
|
||||
) {
|
||||
const { id, status } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page ? page * takeData - takeData : 0;
|
||||
const fixStatusName = _.startCase(status);
|
||||
|
||||
try {
|
||||
@@ -22,6 +27,8 @@ async function GET(
|
||||
name: fixStatusName,
|
||||
},
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeAdminMobile, routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET, DELETE };
|
||||
|
||||
@@ -98,6 +99,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page * takeData - takeData
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
@@ -117,6 +121,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
investasiId: id,
|
||||
active: true,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
try {
|
||||
const data = await prisma.investasi_Invoice.findMany({
|
||||
@@ -29,13 +35,30 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
},
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
const totalData = await prisma.investasi_Invoice.count({
|
||||
where: {
|
||||
investasiId: id,
|
||||
statusInvoiceId: "1",
|
||||
},
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(totalData / takeData);
|
||||
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
success: true,
|
||||
message: "Berhasil Mendapatkan Data",
|
||||
data: data,
|
||||
meta: {
|
||||
currentPage: page,
|
||||
totalData: totalData,
|
||||
totalPage: totalPages,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
NotificationMobileTitleType,
|
||||
NotificationMobileBodyType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET, PUT };
|
||||
|
||||
@@ -53,6 +54,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const authorId = searchParams.get("authorId");
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page ? page * takeData - takeData : 0;
|
||||
|
||||
console.log("[ID INVOICE]", id);
|
||||
|
||||
@@ -103,6 +107,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
statusInvoiceId: "1",
|
||||
isActive: true,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
nominal: true,
|
||||
@@ -129,6 +135,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
where: {
|
||||
authorId: authorId,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
statusInvoiceId: true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import _ from "lodash";
|
||||
import { prisma } from "@/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
import { sendNotificationInvestmentAddNews } from "@/lib/mobile/notification/notification-add-news-investment";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET, DELETE };
|
||||
|
||||
@@ -88,8 +89,13 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
console.log("id", id);
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let fixData;
|
||||
let meta = null;
|
||||
|
||||
try {
|
||||
if (category === "one-news") {
|
||||
const data = await prisma.beritaInvestasi.findFirst({
|
||||
@@ -113,7 +119,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
|
||||
fixData = newData;
|
||||
} else if (category === "all-news") {
|
||||
fixData = await prisma.beritaInvestasi.findMany({
|
||||
const newsData = await prisma.beritaInvestasi.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
@@ -121,7 +127,27 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
investasiId: id,
|
||||
active: true,
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
const totalData = await prisma.beritaInvestasi.count({
|
||||
where: {
|
||||
investasiId: id,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(totalData / takeData);
|
||||
|
||||
fixData = newsData;
|
||||
|
||||
meta = {
|
||||
currentPage: page,
|
||||
totalData: totalData,
|
||||
totalPage: totalPages,
|
||||
dataPerPage: takeData,
|
||||
};
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
@@ -129,6 +155,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
success: true,
|
||||
message: "Berita berhasil diambil",
|
||||
data: fixData,
|
||||
...(meta && { meta }),
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
|
||||
@@ -5,6 +5,7 @@ import moment from "moment";
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
@@ -73,6 +74,9 @@ async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const authorId = searchParams.get("authorId");
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page ? page * takeData - takeData : 0;
|
||||
|
||||
console.log("[CATEGORY]", category);
|
||||
console.log("[AUTHOR ID]", authorId);
|
||||
@@ -132,6 +136,8 @@ async function GET(request: Request) {
|
||||
where: {
|
||||
masterStatusInvestasiId: "1",
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
imageId: true,
|
||||
@@ -156,6 +162,8 @@ async function GET(request: Request) {
|
||||
authorId: authorId,
|
||||
statusInvoiceId: "1",
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
investasiId: true,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -12,6 +13,11 @@ async function GET(
|
||||
const { id, status } = params;
|
||||
const fixStatusName = _.startCase(status);
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page ? page * takeData - takeData : 0;
|
||||
|
||||
const data = await prisma.job.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
@@ -28,13 +34,20 @@ async function GET(
|
||||
id: true,
|
||||
title: true,
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get job",
|
||||
data: data,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
@@ -45,7 +46,7 @@ async function POST(request: Request) {
|
||||
message: "Berhasil disimpan",
|
||||
data: create,
|
||||
},
|
||||
{ status: 201 }
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
@@ -54,7 +55,7 @@ async function POST(request: Request) {
|
||||
message: "Error create job",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,94 +65,129 @@ async function GET(request: Request) {
|
||||
const search = searchParams.get("search");
|
||||
const category = searchParams.get("category");
|
||||
const authorId = searchParams.get("authorId");
|
||||
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
let fixData;
|
||||
|
||||
try {
|
||||
if (category === "archive") {
|
||||
const data = await prisma.job.findMany({
|
||||
where: {
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
isArsip: true,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
// title: {
|
||||
// contains: search || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
authorId: true,
|
||||
MasterStatus: {
|
||||
select: {
|
||||
name: true,
|
||||
const [data, count] = await Promise.all([
|
||||
prisma.job.findMany({
|
||||
where: {
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
isArsip: true,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
// title: {
|
||||
// contains: search || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
authorId: true,
|
||||
MasterStatus: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
}),
|
||||
prisma.job.count({
|
||||
where: {
|
||||
authorId: authorId,
|
||||
isActive: true,
|
||||
isArsip: true,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
fixData = data;
|
||||
} else if (category === "beranda") {
|
||||
const data = await prisma.job.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
authorId: true,
|
||||
MasterStatus: {
|
||||
select: {
|
||||
name: true,
|
||||
const [data, count] = await Promise.all([
|
||||
prisma.job.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
authorId: true,
|
||||
MasterStatus: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
}),
|
||||
prisma.job.count({
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
fixData = data;
|
||||
}
|
||||
@@ -161,8 +197,12 @@ async function GET(request: Request) {
|
||||
success: true,
|
||||
message: "Success get data job-vacancy",
|
||||
data: fixData,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
},
|
||||
{ status: 200 }
|
||||
{ status: 200 },
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
@@ -171,7 +211,7 @@ async function GET(request: Request) {
|
||||
message: "Error get data job-vacancy",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,20 +6,22 @@ import { adminMessaging } from "@/lib/firebase-admin";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: { id: string } },
|
||||
) {
|
||||
const { id } = params;
|
||||
console.log("ID", id);
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
let fixData;
|
||||
const fixCategory = _.upperCase(category || "");
|
||||
|
||||
try {
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = 10;
|
||||
const skipData = page ? page * takeData - takeData : 0;
|
||||
const page = Number(searchParams.get("page"));
|
||||
console.log("page", page);
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let fixData;
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
@@ -69,14 +71,14 @@ export async function GET(
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: { id: string } },
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
@@ -113,7 +115,7 @@ export async function PUT(
|
||||
console.error("Error marking notifications as read:", error);
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -10,14 +11,33 @@ async function GET(
|
||||
) {
|
||||
try {
|
||||
const { id, status } = params;
|
||||
console.log("[ID]", id);
|
||||
const fixStatusName = _.startCase(status);
|
||||
console.log("[STATUS]", fixStatusName);
|
||||
|
||||
let fixData;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let data;
|
||||
let totalCount;
|
||||
|
||||
if (fixStatusName === "Publish") {
|
||||
fixData = await prisma.voting.findMany({
|
||||
data = await prisma.voting.findMany({
|
||||
where: {
|
||||
authorId: id,
|
||||
isActive: true,
|
||||
akhirVote: {
|
||||
gte: new Date(),
|
||||
},
|
||||
Voting_Status: {
|
||||
name: fixStatusName,
|
||||
},
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
totalCount = await prisma.voting.count({
|
||||
where: {
|
||||
authorId: id,
|
||||
isActive: true,
|
||||
@@ -30,7 +50,18 @@ async function GET(
|
||||
},
|
||||
});
|
||||
} else {
|
||||
fixData = await prisma.voting.findMany({
|
||||
data = await prisma.voting.findMany({
|
||||
where: {
|
||||
authorId: id,
|
||||
Voting_Status: {
|
||||
name: fixStatusName,
|
||||
},
|
||||
},
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
});
|
||||
|
||||
totalCount = await prisma.voting.count({
|
||||
where: {
|
||||
authorId: id,
|
||||
Voting_Status: {
|
||||
@@ -40,10 +71,18 @@ async function GET(
|
||||
});
|
||||
}
|
||||
|
||||
const totalPages = Math.ceil(totalCount / takeData);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get voting",
|
||||
data: fixData,
|
||||
data: data,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages: totalPages,
|
||||
totalData: totalCount,
|
||||
dataPerPage: takeData,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
@@ -61,9 +100,7 @@ async function PUT(
|
||||
) {
|
||||
try {
|
||||
const { id, status } = params;
|
||||
console.log("[ID]", id);
|
||||
const fixStatusName = _.startCase(status);
|
||||
console.log("[STATUS]", fixStatusName);
|
||||
|
||||
const checkData = await prisma.voting.findFirst({
|
||||
where: {
|
||||
@@ -79,8 +116,6 @@ async function PUT(
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[CHECKDATA]", checkData);
|
||||
|
||||
if (!checkData)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
@@ -115,8 +150,6 @@ async function PUT(
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[UPDATE]", updateData);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success update voting",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { GET };
|
||||
|
||||
@@ -8,10 +9,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const authorId = searchParams.get("authorId");
|
||||
const category = searchParams.get("category");
|
||||
|
||||
console.log("[ID]", id);
|
||||
console.log("[AUTHOR ID]", authorId);
|
||||
console.log("[CATEGORY]", category);
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page ? page * takeData - takeData : 0;
|
||||
|
||||
let fixData;
|
||||
|
||||
@@ -53,7 +53,10 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
where: {
|
||||
votingId: id,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
select: {
|
||||
id: true,
|
||||
Voting_DaftarNamaVote: {
|
||||
select: {
|
||||
value: true,
|
||||
@@ -75,8 +78,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[LIST KONTRIBUTOR]", listKontributor);
|
||||
|
||||
fixData = listKontributor;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import _ from "lodash";
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
@@ -87,8 +88,9 @@ async function GET(request: Request) {
|
||||
const category = searchParams.get("category");
|
||||
const authorId = searchParams.get("authorId");
|
||||
const userLoginId = searchParams.get("userLoginId");
|
||||
|
||||
console.log("userLoginId >>", userLoginId);
|
||||
const page = Number(searchParams.get("page"));
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
let fixData;
|
||||
|
||||
@@ -123,6 +125,8 @@ async function GET(request: Request) {
|
||||
},
|
||||
},
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
include: {
|
||||
Voting_DaftarNamaVote: {
|
||||
orderBy: {
|
||||
@@ -154,6 +158,8 @@ async function GET(request: Request) {
|
||||
where: {
|
||||
authorId: authorId,
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
include: {
|
||||
Voting: {
|
||||
select: {
|
||||
@@ -211,6 +217,8 @@ async function GET(request: Request) {
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
include: {
|
||||
Voting_DaftarNamaVote: {
|
||||
orderBy: {
|
||||
@@ -249,6 +257,8 @@ async function GET(request: Request) {
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
include: {
|
||||
Voting_DaftarNamaVote: {
|
||||
orderBy: {
|
||||
|
||||
@@ -84,7 +84,7 @@ export async function GET(req: Request) {
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
// Removed prisma.$disconnect() from here to prevent connection pool exhaustion
|
||||
// Prisma connections are handled globally and shouldn't be disconnected on each request
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import { useRouter } from "next/navigation";
|
||||
import { IconMoodSmileFilled } from "@tabler/icons-react";
|
||||
import { listStiker } from "../../lib/stiker";
|
||||
import { UIGlobal_Modal } from "../../ui";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
|
||||
const ReactQuill = dynamic(
|
||||
async () => {
|
||||
@@ -248,10 +249,12 @@ function ButtonAction({ value, lengthData }: ButtonActionProps) {
|
||||
ComponentGlobal_NotifikasiBerhasil(create.message);
|
||||
router.back();
|
||||
|
||||
mqtt_client.publish(
|
||||
"Forum_create_new",
|
||||
JSON.stringify({ isNewPost: true, count: 1 })
|
||||
);
|
||||
if (typeof window !== 'undefined' && mqtt_client) {
|
||||
mqtt_client.publish(
|
||||
"Forum_create_new",
|
||||
JSON.stringify({ isNewPost: true, count: 1 })
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(create.message);
|
||||
}
|
||||
|
||||
1
src/lib/constans-value/constansValue.ts
Normal file
1
src/lib/constans-value/constansValue.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const PAGINATION_DEFAULT_TAKE = 10;
|
||||
@@ -9,30 +9,21 @@ declare global {
|
||||
let prisma: PrismaClient;
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
prisma = new PrismaClient();
|
||||
prisma = new PrismaClient({
|
||||
// Reduce logging in production to improve performance
|
||||
log: ['error', 'warn'],
|
||||
});
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient();
|
||||
global.prisma = new PrismaClient({
|
||||
log: ['error', 'warn', 'info', 'query'], // More verbose logging in development
|
||||
});
|
||||
}
|
||||
prisma = global.prisma;
|
||||
}
|
||||
|
||||
// Tambahkan listener hanya jika belum ditambahkan sebelumnya
|
||||
if (!global.prismaListenersAdded) {
|
||||
// Handle uncaught errors
|
||||
process.on("uncaughtException", async (error) => {
|
||||
console.error("Uncaught Exception:", error);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Handle unhandled promise rejections
|
||||
process.on("unhandledRejection", async (error) => {
|
||||
console.error("Unhandled Rejection:", error);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on("SIGINT", async () => {
|
||||
console.log("Received SIGINT signal. Closing database connections...");
|
||||
@@ -51,3 +42,4 @@ if (!global.prismaListenersAdded) {
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
export { prisma };
|
||||
|
||||
24
src/lib/prismaUtils.ts
Normal file
24
src/lib/prismaUtils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { prisma } from './prisma';
|
||||
|
||||
/**
|
||||
* Utility function to safely execute Prisma operations
|
||||
* This prevents improper disconnection of the Prisma client
|
||||
* which was causing high CPU usage and connection pool issues
|
||||
*/
|
||||
export async function executeDbOperation<T>(
|
||||
operation: () => Promise<T>,
|
||||
errorMessage: string = "Database operation failed"
|
||||
): Promise<{ success: boolean; data?: T; error?: string }> {
|
||||
try {
|
||||
const data = await operation();
|
||||
return { success: true, data };
|
||||
} catch (error) {
|
||||
console.error(errorMessage, error);
|
||||
return { success: false, error: (error as Error).message };
|
||||
}
|
||||
// Note: We intentionally do NOT call prisma.$disconnect() here
|
||||
// Prisma manages connection pooling automatically and disconnecting
|
||||
// on each request causes performance issues
|
||||
}
|
||||
|
||||
export { prisma };
|
||||
@@ -66,9 +66,10 @@ export const middleware = async (req: NextRequest) => {
|
||||
const { pathname } = req.nextUrl;
|
||||
|
||||
const apiBaseUrl = new URL(req.url).origin || process.env.NEXT_PUBLIC_API_URL;
|
||||
const dbUrl = process.env.DATABASE_URL;
|
||||
console.log("DATABASE_URL >>", dbUrl);
|
||||
console.log("URL Access >>", req.url);
|
||||
// Removed excessive logging that was causing high CPU usage
|
||||
// const dbUrl = process.env.DATABASE_URL;
|
||||
// console.log("DATABASE_URL >>", dbUrl);
|
||||
// console.log("URL Access >>", req.url);
|
||||
|
||||
// Handle CORS preflight
|
||||
const corsResponse = handleCors(req);
|
||||
|
||||
@@ -4,7 +4,66 @@ declare global {
|
||||
var mqtt_client: mqtt.MqttClient;
|
||||
}
|
||||
|
||||
const mqtt_client =
|
||||
globalThis.mqtt_client || mqtt.connect("wss://io.wibudev.com");
|
||||
// Initialize MQTT client with proper error handling and reconnection settings
|
||||
let mqtt_client: mqtt.MqttClient;
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
// Server-side code
|
||||
mqtt_client = globalThis.mqtt_client || (() => {
|
||||
const client = mqtt.connect("wss://io.wibudev.com", {
|
||||
reconnectPeriod: 5000, // Reconnect every 5 seconds
|
||||
connectTimeout: 30 * 1000, // 30 second timeout
|
||||
// Clean session to avoid message queue buildup
|
||||
clean: true,
|
||||
// Reduce unnecessary pings
|
||||
keepalive: 60
|
||||
});
|
||||
|
||||
// Prevent multiple initializations
|
||||
globalThis.mqtt_client = client;
|
||||
|
||||
// Add error handling
|
||||
client.on('error', (error) => {
|
||||
console.error('MQTT Connection Error:', error);
|
||||
});
|
||||
|
||||
client.on('reconnect', () => {
|
||||
console.log('MQTT Reconnecting...');
|
||||
});
|
||||
|
||||
client.on('close', () => {
|
||||
console.log('MQTT Connection Closed');
|
||||
});
|
||||
|
||||
return client;
|
||||
})();
|
||||
} else {
|
||||
// Client-side code - initialize only once
|
||||
if (!(globalThis as any).mqtt_client) {
|
||||
(globalThis as any).mqtt_client = mqtt.connect("wss://io.wibudev.com", {
|
||||
reconnectPeriod: 5000, // Reconnect every 5 seconds
|
||||
connectTimeout: 30 * 1000, // 30 second timeout
|
||||
// Clean session to avoid message queue buildup
|
||||
clean: true,
|
||||
// Reduce unnecessary pings
|
||||
keepalive: 60
|
||||
});
|
||||
|
||||
// Add error handling
|
||||
(globalThis as any).mqtt_client.on('error', (error: any) => {
|
||||
console.error('MQTT Connection Error:', error);
|
||||
});
|
||||
|
||||
(globalThis as any).mqtt_client.on('reconnect', () => {
|
||||
console.log('MQTT Reconnecting...');
|
||||
});
|
||||
|
||||
(globalThis as any).mqtt_client.on('close', () => {
|
||||
console.log('MQTT Connection Closed');
|
||||
});
|
||||
}
|
||||
|
||||
mqtt_client = (globalThis as any).mqtt_client;
|
||||
}
|
||||
|
||||
export default mqtt_client;
|
||||
|
||||
@@ -3,20 +3,27 @@
|
||||
import { useEffect } from "react";
|
||||
import mqtt_client from "./mqtt_client";
|
||||
|
||||
export default function MqttLoader() {
|
||||
export default function MqttLoader() {
|
||||
useEffect(() => {
|
||||
mqtt_client.on("connect", () => {
|
||||
console.log("connected");
|
||||
});
|
||||
// Only set up connection handlers once
|
||||
const handleConnect = () => {
|
||||
console.log("MQTT connected");
|
||||
};
|
||||
|
||||
const handleError = (error: any) => {
|
||||
console.error("MQTT Error:", error);
|
||||
};
|
||||
|
||||
// Subscribe to events
|
||||
mqtt_client.on("connect", handleConnect);
|
||||
mqtt_client.on("error", handleError);
|
||||
|
||||
// Cleanup function to unsubscribe when component unmounts
|
||||
return () => {
|
||||
mqtt_client.off("connect", handleConnect);
|
||||
mqtt_client.off("error", handleError);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
|
||||
// <>
|
||||
// <Stack>
|
||||
// <Button onClick={onClick}>Tekan</Button>
|
||||
// <Button onClick={onClick2}>Tekan 2</Button>
|
||||
// </Stack>
|
||||
// </>
|
||||
// );
|
||||
}
|
||||
|
||||
226
zCoba.js
226
zCoba.js
@@ -1,28 +1,204 @@
|
||||
// const data = [
|
||||
// {
|
||||
// authorId: "clx8pl7r90005su4mldioo0v1",
|
||||
// Donasi: {
|
||||
// id: "clyr304q0000410ljvzms3mag",
|
||||
// title: "Donasi Bencana Alam Aceh",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// authorId: "clx8pl7r90005su4mldioo0v1",
|
||||
// Donasi: {
|
||||
// id: "clyr304q0000410ljvzms3mag",
|
||||
// title: "Donasi Bencana Alam Aceh",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// authorId: "clycka5eu0001ina3i1ssgze9",
|
||||
// Donasi: {
|
||||
// id: "clyr304q0000410ljvzms3mag",
|
||||
// title: "Donasi Bencana Alam Aceh",
|
||||
// },
|
||||
// },
|
||||
// ];
|
||||
const { PrismaClient } = require('@prisma/client')
|
||||
const axios = require('axios')
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
console.error("errornya disini klik aja",import.meta.url);
|
||||
console.log(new Set(data.map((d) => d.authorId)));
|
||||
// Daftar contoh data
|
||||
const donationDataList = [
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Bantuan Pendidikan Anak-anak Kurang Mampu",
|
||||
"target": 50000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Central Asia",
|
||||
"rekening": "1234567890",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Kami ingin membantu anak-anak kurang mampu mendapatkan pendidikan yang layak.",
|
||||
"cerita": "Pendidikan adalah hak dasar setiap anak. Namun, banyak anak-anak di pelosok negeri yang tidak bisa menikmati pendidikan karena keterbatasan ekonomi. Melalui kampanye ini, kami ingin mengumpulkan dana untuk membantu biaya pendidikan mereka.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Pembangunan Masjid di Desa Terpencil",
|
||||
"target": 100000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Mandiri",
|
||||
"rekening": "0987654321",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Membangun masjid untuk masyarakat di daerah terpencil yang belum memiliki tempat ibadah.",
|
||||
"cerita": "Di sebuah desa terpencil, masyarakat setiap hari harus berjalan jauh untuk bisa melaksanakan sholat berjamaah. Kami ingin membantu membangun masjid di tengah-tengah mereka agar ibadah bisa dilakukan dengan lebih tenang dan khusyuk.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Bantuan Korban Bencana Alam",
|
||||
"target": 75000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Rakyat Indonesia",
|
||||
"rekening": "5678901234",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Membantu meringankan beban korban bencana alam berupa kebutuhan pokok dan kebutuhan darurat.",
|
||||
"cerita": "Beberapa wilayah dilanda bencana banjir dan tanah longsor. Masyarakat kehilangan harta benda dan membutuhkan bantuan segera. Dana yang terkumpul akan digunakan untuk menyediakan makanan, obat-obatan, dan kebutuhan pokok lainnya.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Pengadaan Alat Medis Rumah Sakit",
|
||||
"target": 150000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Negara Indonesia",
|
||||
"rekening": "4321098765",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Meningkatkan kualitas pelayanan kesehatan dengan menyediakan alat medis yang lebih baik.",
|
||||
"cerita": "Rumah sakit daerah kekurangan alat medis untuk melayani pasien. Melalui donasi ini, kami ingin membantu pengadaan alat-alat medis penting seperti ventilator, USG, dan alat laboratorium untuk meningkatkan kualitas pelayanan kesehatan.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Program Beasiswa Mahasiswa Berprestasi",
|
||||
"target": 80000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Danamon",
|
||||
"rekening": "1122334455",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Memberikan kesempatan kepada mahasiswa berprestasi untuk melanjutkan pendidikan tanpa beban biaya.",
|
||||
"cerita": "Banyak mahasiswa berprestasi yang tidak mampu melanjutkan pendidikan karena keterbatasan biaya. Program beasiswa ini akan membantu mereka menyelesaikan kuliah hingga sarjana.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Pengadaan Air Bersih untuk Desa Kekeringan",
|
||||
"target": 60000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Permata",
|
||||
"rekening": "6677889900",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Menyediakan akses air bersih bagi masyarakat yang tinggal di daerah rawan kekeringan.",
|
||||
"cerita": "Beberapa desa mengalami kekeringan setiap tahunnya, membuat warga kesulitan mendapatkan air bersih. Kami ingin membangun sumur bor dan sistem distribusi air untuk membantu masyarakat setempat.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj5"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Pengobatan Gratis untuk Warga Tidak Mampu",
|
||||
"target": 40000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Panin",
|
||||
"rekening": "9988776655",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Memberikan layanan kesehatan gratis bagi warga yang tidak mampu membayar biaya pengobatan.",
|
||||
"cerita": "Banyak warga yang menunda pengobatan karena keterbatasan biaya. Melalui program ini, kami akan menyelenggarakan pengobatan gratis secara berkala di berbagai wilayah.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Pembangunan Taman Bacaan Masyarakat",
|
||||
"target": 35000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank Mega",
|
||||
"rekening": "1357924680",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Membangun taman bacaan untuk meningkatkan minat baca masyarakat di wilayah pedesaan.",
|
||||
"cerita": "Minat baca masyarakat di pedesaan masih rendah karena keterbatasan akses buku. Taman bacaan ini akan menyediakan ribuan buku gratis dan ruang baca yang nyaman untuk semua usia.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Pelatihan Keterampilan untuk Pengangguran",
|
||||
"target": 55000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank CIMB Niaga",
|
||||
"rekening": "2468135790",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Memberikan pelatihan keterampilan untuk membantu pengangguran mendapatkan pekerjaan atau usaha mandiri.",
|
||||
"cerita": "Angka pengangguran masih tinggi di beberapa wilayah. Program pelatihan ini akan memberikan keterampilan yang dibutuhkan pasar kerja, seperti menjahit, memasak, teknologi informasi, dan lainnya.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"authorId": "cmha6wb9w0001cfndwl9fcse6",
|
||||
"title": "Renovasi Gedung Sekolah Rusak",
|
||||
"target": 90000000,
|
||||
"donasiMaster_DurasiId": 3,
|
||||
"donasiMaster_KategoriId": 3,
|
||||
"namaBank": "Bank OCBC NISP",
|
||||
"rekening": "1029384756",
|
||||
"imageId": "cm60j9q3m000xc9dc584v8rh8",
|
||||
"pembukaan": "Merestrukturasi gedung sekolah yang rusak agar siswa bisa belajar dengan aman dan nyaman.",
|
||||
"cerita": "Banyak gedung sekolah yang rusak parah dan membahayakan keselamatan siswa. Dana dari kampanye ini akan digunakan untuk renovasi dan perbaikan gedung sekolah yang membutuhkan.",
|
||||
"imageCeritaId": "cm60j9q3m000xc9dc584v8rj9"
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
async function sendDonationData() {
|
||||
const baseUrl = 'http://localhost:3000/api/mobile/donation'; // Sesuaikan dengan URL server Anda
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
for (let i = 0; i < donationDataList.length; i++) {
|
||||
try {
|
||||
console.log(`Mengirim data ke-${i + 1}...`);
|
||||
const response = await axios.post(`${baseUrl}?category=permanent`, donationDataList[i], {
|
||||
headers: headers
|
||||
});
|
||||
console.log(`Data ke-${i + 1} berhasil dikirim:`, response.data);
|
||||
} catch (error) {
|
||||
console.error(`Error saat mengirim data ke-${i + 1}:`, error.response?.data || error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// Menjalankan fungsi untuk mengirim data donasi
|
||||
await sendDonationData();
|
||||
|
||||
// Fungsi asli untuk update notifikasi
|
||||
const result = await prisma.notifikasi.updateMany({
|
||||
where: {
|
||||
recipientId: 'cmha7p6yc0000cfoe5w2e7gdr',
|
||||
},
|
||||
data: {
|
||||
isRead: false,
|
||||
readAt: null,
|
||||
},
|
||||
})
|
||||
|
||||
console.log(`✅ Rows affected: ${result.count}`)
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((err) => {
|
||||
console.error('❌ Error:', err)
|
||||
process.exit(1)
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user