Compare commits

...

3 Commits

Author SHA1 Message Date
6aceb212e4 Fix APi voting mobile laod data
API – Event (Mobile)
- src/app/api/mobile/event/route.ts
- src/app/api/mobile/event/[id]/[status]/route.ts
- src/app/api/mobile/event/[id]/participants/route.ts

API – Voting (Mobile)
- src/app/api/mobile/voting/[id]/[status]/route.ts

Docs
- PROMPT-AI.md

### No Issue
2026-02-04 17:49:32 +08:00
42803f9b92 Fix api load data event dan notifikasi
API – Event (Mobile)
- src/app/api/mobile/event/route.ts
- src/app/api/mobile/event/[id]/[status]/route.ts

API – Notification (Mobile)
- src/app/api/mobile/notification/[id]/route.ts

Docs / Experiment
- PROMPT-AI.md
- zCoba.js

### No issue
2026-02-03 17:50:07 +08:00
2a857f54e7 Fix API Job untuk loaddata:
API – Job (Mobile)
- src/app/api/mobile/job/route.ts
- src/app/api/mobile/job/[id]/[status]/route.ts

Docs
- PROMPT-AI.md

Constants
- src/lib/constans-value/

### No Issue
2026-02-02 17:03:51 +08:00
10 changed files with 426 additions and 246 deletions

View File

@@ -1,5 +1,5 @@
File utama: src/app/api/mobile/notification/[id]/route.ts
File utama: src/app/api/mobile/voting/[id]/[status]/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,7 @@ 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

View File

@@ -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 }
);

View File

@@ -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 },
);
}
}

View File

@@ -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 }
);

View File

@@ -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 }
);

View File

@@ -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 },
);
}
}

View File

@@ -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 },
);
}
}

View File

@@ -14,10 +14,31 @@ async function GET(
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 = 10;
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 +51,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 +72,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);

View File

@@ -0,0 +1 @@
export const PAGINATION_DEFAULT_TAKE = 10;

View File

@@ -1,28 +1,26 @@
// 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 prisma = new PrismaClient()
console.error("errornya disini klik aja",import.meta.url);
console.log(new Set(data.map((d) => d.authorId)));
async function main() {
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()
})