Fix API mobile #51
@@ -1,5 +1,5 @@
|
||||
|
||||
File utama: src/app/api/mobile/voting/[id]/[status]/route.ts
|
||||
File utama: src/app/api/mobile/voting/[id]/contribution/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
|
||||
|
||||
@@ -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,13 +11,11 @@ async function GET(
|
||||
) {
|
||||
try {
|
||||
const { id, status } = params;
|
||||
console.log("[ID]", id);
|
||||
const fixStatusName = _.startCase(status);
|
||||
console.log("[STATUS]", fixStatusName);
|
||||
|
||||
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;
|
||||
|
||||
let data;
|
||||
@@ -101,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: {
|
||||
@@ -119,8 +116,6 @@ async function PUT(
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[CHECKDATA]", checkData);
|
||||
|
||||
if (!checkData)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
@@ -155,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