Compare commits
3 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 097758a431 | |||
| 6f5849aa29 | |||
| 6aceb212e4 |
@@ -1,6 +1,5 @@
|
||||
|
||||
File utama: src/app/api/mobile/event/route.ts
|
||||
File refrensi: src/app/api/mobile/job/[id]/[status]/route.ts
|
||||
File utama: src/app/api/mobile/investment/[id]/invoice/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,6 +13,8 @@ dan penerapannya pada query
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
|
||||
Anda bisa menggunakan refrensi dari "File refrensi" jika butuh pemahaman dengan tipe fitur yang sama
|
||||
|
||||
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
|
||||
@@ -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 };
|
||||
|
||||
@@ -14,7 +15,7 @@ async function GET(
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = 10;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -77,7 +78,7 @@ async function GET(request: Request) {
|
||||
const category = searchParams.get("category");
|
||||
const userId = searchParams.get("userId");
|
||||
const page = Number(searchParams.get("page")) || 1;
|
||||
const takeData = 5;
|
||||
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
console.log("[CAT]", category);
|
||||
@@ -165,6 +166,7 @@ async function GET(request: Request) {
|
||||
userId: userId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
eventId: true,
|
||||
userId: true,
|
||||
Event: {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,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: {
|
||||
|
||||
Reference in New Issue
Block a user