Compare commits
4 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 097758a431 | |||
| 6f5849aa29 | |||
| 6aceb212e4 | |||
| 42803f9b92 |
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
File utama: src/app/api/mobile/job/route.ts
|
File utama: src/app/api/mobile/investment/[id]/invoice/route.ts
|
||||||
|
|
||||||
Terapkan pagination pada file "File utama" pada method GET
|
Terapkan pagination pada file "File utama" pada method GET
|
||||||
Analisa juga file "File utama", jika belum memiliki page dari seachParams maka terapkan. Juga pastikan take dan skip sudah sesuai dengan pagination. Buat default nya menjadi 10 untuk take data
|
Analisa juga file "File utama", jika belum memiliki page dari seachParams maka terapkan. Juga pastikan take dan skip sudah sesuai dengan pagination. Buat default nya menjadi 10 untuk take data
|
||||||
@@ -14,3 +14,7 @@ take: page ? takeData : undefined,
|
|||||||
skip: page ? skipData : undefined,
|
skip: page ? skipData : undefined,
|
||||||
|
|
||||||
Gunakan bahasa indonesia pada cli agar saya mudah membacanya.
|
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 { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
@@ -12,6 +13,11 @@ async function GET(
|
|||||||
const { id, status } = params;
|
const { id, status } = params;
|
||||||
const fixStatusName = _.startCase(status);
|
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({
|
const data = await prisma.event.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
updatedAt: "desc",
|
updatedAt: "desc",
|
||||||
@@ -37,13 +43,35 @@ async function GET(
|
|||||||
},
|
},
|
||||||
authorId: true,
|
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(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success get event",
|
message: "Success get event",
|
||||||
data: data,
|
data: data,
|
||||||
|
pagination: {
|
||||||
|
currentPage: page,
|
||||||
|
totalPages: totalPages,
|
||||||
|
totalData: totalCount,
|
||||||
|
dataPerPage: takeData,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
NotificationMobileTitleType,
|
NotificationMobileTitleType,
|
||||||
} from "../../../../../../../types/type-mobile-notification";
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
message: "Success join event",
|
message: "Success join event",
|
||||||
data: createJoin,
|
data: createJoin,
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 },
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -56,7 +57,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
message: "Error join event",
|
message: "Error join event",
|
||||||
reason: (error as Error).message,
|
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 } }) {
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const { id } = params;
|
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({
|
const data = await prisma.event_Peserta.findMany({
|
||||||
where: {
|
where: {
|
||||||
eventId: id,
|
eventId: id,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
eventId: true,
|
eventId: true,
|
||||||
userId: true,
|
userId: true,
|
||||||
isPresent: true,
|
isPresent: true,
|
||||||
@@ -87,6 +93,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: takeData,
|
||||||
|
skip: skipData,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -94,8 +102,14 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
success: true,
|
success: true,
|
||||||
message: "Success get participants",
|
message: "Success get participants",
|
||||||
data: data,
|
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) {
|
} catch (error) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -104,7 +118,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
message: "Error get participants",
|
message: "Error get participants",
|
||||||
reason: (error as Error).message,
|
reason: (error as Error).message,
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import _ from "lodash";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, POST };
|
export { GET, POST };
|
||||||
|
|
||||||
@@ -76,11 +77,15 @@ async function GET(request: Request) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const userId = searchParams.get("userId");
|
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("[CAT]", category);
|
||||||
console.log("[USER]", userId);
|
console.log("[USER]", userId);
|
||||||
|
|
||||||
let fixData;
|
let fixData;
|
||||||
|
let totalCount = 0;
|
||||||
|
|
||||||
if (category === "beranda") {
|
if (category === "beranda") {
|
||||||
const allData = await prisma.event.findMany({
|
const allData = await prisma.event.findMany({
|
||||||
@@ -108,84 +113,96 @@ async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const takeData = 10;
|
const [data, count] = await Promise.all([
|
||||||
// const skipData = page * takeData - takeData;
|
prisma.event.findMany({
|
||||||
|
take: takeData,
|
||||||
const data = await prisma.event.findMany({
|
skip: skipData,
|
||||||
// take: takeData,
|
orderBy: [
|
||||||
// skip: skipData,
|
{
|
||||||
orderBy: [
|
tanggal: "asc",
|
||||||
{
|
},
|
||||||
tanggal: "asc",
|
],
|
||||||
|
where: {
|
||||||
|
active: true,
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: false,
|
||||||
},
|
},
|
||||||
],
|
select: {
|
||||||
where: {
|
id: true,
|
||||||
active: true,
|
title: true,
|
||||||
eventMaster_StatusId: "1",
|
deskripsi: true,
|
||||||
isArsip: false,
|
tanggal: true,
|
||||||
},
|
tanggalSelesai: true,
|
||||||
select: {
|
EventMaster_Status: {
|
||||||
id: true,
|
select: {
|
||||||
title: true,
|
name: true,
|
||||||
deskripsi: true,
|
},
|
||||||
tanggal: true,
|
},
|
||||||
tanggalSelesai: true,
|
authorId: true,
|
||||||
EventMaster_Status: {
|
Author: {
|
||||||
select: {
|
include: {
|
||||||
name: true,
|
Profile: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authorId: true,
|
}),
|
||||||
Author: {
|
prisma.event.count({
|
||||||
include: {
|
where: {
|
||||||
Profile: true,
|
active: true,
|
||||||
},
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: false,
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
});
|
]);
|
||||||
|
|
||||||
fixData = data;
|
fixData = data;
|
||||||
|
totalCount = count;
|
||||||
} else if (category === "contribution") {
|
} else if (category === "contribution") {
|
||||||
const data = await prisma.event_Peserta.findMany({
|
const [data, count] = await Promise.all([
|
||||||
where: {
|
prisma.event_Peserta.findMany({
|
||||||
userId: userId,
|
take: takeData,
|
||||||
},
|
skip: skipData,
|
||||||
select: {
|
where: {
|
||||||
eventId: true,
|
userId: userId,
|
||||||
userId: true,
|
},
|
||||||
Event: {
|
select: {
|
||||||
select: {
|
id: true,
|
||||||
id: true,
|
eventId: true,
|
||||||
title: true,
|
userId: true,
|
||||||
tanggal: true,
|
Event: {
|
||||||
Author: {
|
select: {
|
||||||
select: {
|
id: true,
|
||||||
id: true,
|
title: true,
|
||||||
username: true,
|
tanggal: true,
|
||||||
Profile: {
|
Author: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
username: true,
|
||||||
imageId: true,
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
Event_Peserta: {
|
||||||
Event_Peserta: {
|
take: 4,
|
||||||
take: 4,
|
orderBy: {
|
||||||
orderBy: {
|
createdAt: "desc",
|
||||||
createdAt: "desc",
|
},
|
||||||
},
|
select: {
|
||||||
select: {
|
id: true,
|
||||||
id: true,
|
userId: true,
|
||||||
userId: true,
|
User: {
|
||||||
User: {
|
select: {
|
||||||
select: {
|
Profile: {
|
||||||
Profile: {
|
select: {
|
||||||
select: {
|
id: true,
|
||||||
id: true,
|
name: true,
|
||||||
name: true,
|
imageId: true,
|
||||||
imageId: true,
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -194,86 +211,109 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
}),
|
||||||
// User: {
|
prisma.event_Peserta.count({
|
||||||
// select: {
|
where: {
|
||||||
// id: true,
|
userId: userId,
|
||||||
// username: true,
|
},
|
||||||
// Profile: {
|
})
|
||||||
// select: {
|
]);
|
||||||
// id: true,
|
|
||||||
// name: true,
|
|
||||||
// imageId: true,
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
fixData = data;
|
fixData = data;
|
||||||
|
totalCount = count;
|
||||||
} else if (category === "all-history") {
|
} else if (category === "all-history") {
|
||||||
const data = await prisma.event.findMany({
|
const [data, count] = await Promise.all([
|
||||||
orderBy: {
|
prisma.event.findMany({
|
||||||
tanggal: "desc",
|
take: takeData,
|
||||||
},
|
skip: skipData,
|
||||||
where: {
|
orderBy: {
|
||||||
eventMaster_StatusId: "1",
|
tanggal: "desc",
|
||||||
isArsip: true,
|
},
|
||||||
},
|
where: {
|
||||||
select: {
|
eventMaster_StatusId: "1",
|
||||||
id: true,
|
isArsip: true,
|
||||||
title: true,
|
},
|
||||||
tanggal: true,
|
select: {
|
||||||
deskripsi: true,
|
id: true,
|
||||||
active: true,
|
title: true,
|
||||||
authorId: true,
|
tanggal: true,
|
||||||
Author: {
|
deskripsi: true,
|
||||||
select: {
|
active: true,
|
||||||
id: true,
|
authorId: true,
|
||||||
username: true,
|
Author: {
|
||||||
Profile: true,
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}),
|
||||||
});
|
prisma.event.count({
|
||||||
|
where: {
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
fixData = data;
|
fixData = data;
|
||||||
|
totalCount = count;
|
||||||
} else if (category === "my-history") {
|
} else if (category === "my-history") {
|
||||||
const data = await prisma.event.findMany({
|
const [data, count] = await Promise.all([
|
||||||
orderBy: {
|
prisma.event.findMany({
|
||||||
tanggal: "desc",
|
take: takeData,
|
||||||
},
|
skip: skipData,
|
||||||
where: {
|
orderBy: {
|
||||||
authorId: userId,
|
tanggal: "desc",
|
||||||
eventMaster_StatusId: "1",
|
},
|
||||||
isArsip: true,
|
where: {
|
||||||
},
|
authorId: userId,
|
||||||
select: {
|
eventMaster_StatusId: "1",
|
||||||
id: true,
|
isArsip: true,
|
||||||
title: true,
|
},
|
||||||
tanggal: true,
|
select: {
|
||||||
deskripsi: true,
|
id: true,
|
||||||
active: true,
|
title: true,
|
||||||
authorId: true,
|
tanggal: true,
|
||||||
Author: {
|
deskripsi: true,
|
||||||
select: {
|
active: true,
|
||||||
id: true,
|
authorId: true,
|
||||||
username: true,
|
Author: {
|
||||||
Profile: true,
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}),
|
||||||
});
|
prisma.event.count({
|
||||||
|
where: {
|
||||||
|
authorId: userId,
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
fixData = data;
|
fixData = data;
|
||||||
|
totalCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(totalCount / takeData);
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success get event",
|
message: "Success get event",
|
||||||
data: fixData,
|
data: fixData,
|
||||||
|
pagination: {
|
||||||
|
currentPage: page,
|
||||||
|
totalPages: totalPages,
|
||||||
|
totalData: totalCount,
|
||||||
|
dataPerPage: takeData,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
@@ -9,6 +10,10 @@ async function GET(
|
|||||||
{ params }: { params: { id: string; status: string } }
|
{ params }: { params: { id: string; status: string } }
|
||||||
) {
|
) {
|
||||||
const { id, status } = params;
|
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);
|
const fixStatusName = _.startCase(status);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -22,6 +27,8 @@ async function GET(
|
|||||||
name: fixStatusName,
|
name: fixStatusName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
NotificationMobileTitleType,
|
NotificationMobileTitleType,
|
||||||
} from "../../../../../../../types/type-mobile-notification";
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
import { routeAdminMobile, routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
import { routeAdminMobile, routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { POST, GET, DELETE };
|
export { POST, GET, DELETE };
|
||||||
|
|
||||||
@@ -98,6 +99,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = PAGINATION_DEFAULT_TAKE
|
||||||
|
const skipData = page * takeData - takeData
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let fixData;
|
let fixData;
|
||||||
@@ -117,6 +121,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
investasiId: id,
|
investasiId: id,
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
NotificationMobileTitleType,
|
NotificationMobileTitleType,
|
||||||
NotificationMobileBodyType,
|
NotificationMobileBodyType,
|
||||||
} from "../../../../../../../types/type-mobile-notification";
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { POST, GET, PUT };
|
export { POST, GET, PUT };
|
||||||
|
|
||||||
@@ -53,6 +54,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const authorId = searchParams.get("authorId");
|
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);
|
console.log("[ID INVOICE]", id);
|
||||||
|
|
||||||
@@ -103,6 +107,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
statusInvoiceId: "1",
|
statusInvoiceId: "1",
|
||||||
isActive: true,
|
isActive: true,
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
nominal: true,
|
nominal: true,
|
||||||
@@ -129,6 +135,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
where: {
|
where: {
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
statusInvoiceId: true,
|
statusInvoiceId: true,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import moment from "moment";
|
|||||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { POST, GET };
|
export { POST, GET };
|
||||||
|
|
||||||
@@ -73,6 +74,9 @@ async function GET(request: Request) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const authorId = searchParams.get("authorId");
|
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("[CATEGORY]", category);
|
||||||
console.log("[AUTHOR ID]", authorId);
|
console.log("[AUTHOR ID]", authorId);
|
||||||
@@ -132,6 +136,8 @@ async function GET(request: Request) {
|
|||||||
where: {
|
where: {
|
||||||
masterStatusInvestasiId: "1",
|
masterStatusInvestasiId: "1",
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
imageId: true,
|
imageId: true,
|
||||||
@@ -156,6 +162,8 @@ async function GET(request: Request) {
|
|||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
statusInvoiceId: "1",
|
statusInvoiceId: "1",
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
investasiId: true,
|
investasiId: true,
|
||||||
|
|||||||
@@ -6,20 +6,22 @@ import { adminMessaging } from "@/lib/firebase-admin";
|
|||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: { id: string } },
|
||||||
) {
|
) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
console.log("ID", id);
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
|
|
||||||
let fixData;
|
|
||||||
const fixCategory = _.upperCase(category || "");
|
const fixCategory = _.upperCase(category || "");
|
||||||
|
|
||||||
try {
|
const page = Number(searchParams.get("page"));
|
||||||
const page = Number(searchParams.get("page"));
|
console.log("page", page);
|
||||||
const takeData = 10;
|
const takeData = 10;
|
||||||
const skipData = page ? page * takeData - takeData : 0;
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
|
let fixData;
|
||||||
|
|
||||||
|
try {
|
||||||
const data = await prisma.notifikasi.findMany({
|
const data = await prisma.notifikasi.findMany({
|
||||||
take: page ? takeData : undefined,
|
take: page ? takeData : undefined,
|
||||||
skip: page ? skipData : undefined,
|
skip: page ? skipData : undefined,
|
||||||
@@ -69,14 +71,14 @@ export async function GET(
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: (error as Error).message },
|
{ error: (error as Error).message },
|
||||||
{ status: 500 }
|
{ status: 500 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function PUT(
|
export async function PUT(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: { id: string } },
|
||||||
) {
|
) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
@@ -113,7 +115,7 @@ export async function PUT(
|
|||||||
console.error("Error marking notifications as read:", error);
|
console.error("Error marking notifications as read:", error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: (error as Error).message },
|
{ error: (error as Error).message },
|
||||||
{ status: 500 }
|
{ status: 500 },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
@@ -10,14 +11,33 @@ async function GET(
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const { id, status } = params;
|
const { id, status } = params;
|
||||||
console.log("[ID]", id);
|
|
||||||
const fixStatusName = _.startCase(status);
|
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") {
|
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: {
|
where: {
|
||||||
authorId: id,
|
authorId: id,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -30,7 +50,18 @@ async function GET(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} 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: {
|
where: {
|
||||||
authorId: id,
|
authorId: id,
|
||||||
Voting_Status: {
|
Voting_Status: {
|
||||||
@@ -40,10 +71,18 @@ async function GET(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(totalCount / takeData);
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success get voting",
|
message: "Success get voting",
|
||||||
data: fixData,
|
data: data,
|
||||||
|
pagination: {
|
||||||
|
currentPage: page,
|
||||||
|
totalPages: totalPages,
|
||||||
|
totalData: totalCount,
|
||||||
|
dataPerPage: takeData,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("[ERROR]", error);
|
console.log("[ERROR]", error);
|
||||||
@@ -61,9 +100,7 @@ async function PUT(
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const { id, status } = params;
|
const { id, status } = params;
|
||||||
console.log("[ID]", id);
|
|
||||||
const fixStatusName = _.startCase(status);
|
const fixStatusName = _.startCase(status);
|
||||||
console.log("[STATUS]", fixStatusName);
|
|
||||||
|
|
||||||
const checkData = await prisma.voting.findFirst({
|
const checkData = await prisma.voting.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -79,8 +116,6 @@ async function PUT(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[CHECKDATA]", checkData);
|
|
||||||
|
|
||||||
if (!checkData)
|
if (!checkData)
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -115,8 +150,6 @@ async function PUT(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[UPDATE]", updateData);
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success update voting",
|
message: "Success update voting",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { GET };
|
export { GET };
|
||||||
|
|
||||||
@@ -8,10 +9,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const authorId = searchParams.get("authorId");
|
const authorId = searchParams.get("authorId");
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
console.log("[ID]", id);
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
console.log("[AUTHOR ID]", authorId);
|
const skipData = page ? page * takeData - takeData : 0;
|
||||||
console.log("[CATEGORY]", category);
|
|
||||||
|
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
@@ -53,7 +53,10 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
where: {
|
where: {
|
||||||
votingId: id,
|
votingId: id,
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
Voting_DaftarNamaVote: {
|
Voting_DaftarNamaVote: {
|
||||||
select: {
|
select: {
|
||||||
value: true,
|
value: true,
|
||||||
@@ -75,8 +78,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[LIST KONTRIBUTOR]", listKontributor);
|
|
||||||
|
|
||||||
fixData = listKontributor;
|
fixData = listKontributor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import _ from "lodash";
|
|||||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import { PAGINATION_DEFAULT_TAKE } from "@/lib/constans-value/constansValue";
|
||||||
|
|
||||||
export { POST, GET };
|
export { POST, GET };
|
||||||
|
|
||||||
@@ -87,8 +88,9 @@ async function GET(request: Request) {
|
|||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
const authorId = searchParams.get("authorId");
|
const authorId = searchParams.get("authorId");
|
||||||
const userLoginId = searchParams.get("userLoginId");
|
const userLoginId = searchParams.get("userLoginId");
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
console.log("userLoginId >>", userLoginId);
|
const takeData = PAGINATION_DEFAULT_TAKE;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
@@ -123,6 +125,8 @@ async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
include: {
|
include: {
|
||||||
Voting_DaftarNamaVote: {
|
Voting_DaftarNamaVote: {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@@ -154,6 +158,8 @@ async function GET(request: Request) {
|
|||||||
where: {
|
where: {
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
include: {
|
include: {
|
||||||
Voting: {
|
Voting: {
|
||||||
select: {
|
select: {
|
||||||
@@ -211,6 +217,8 @@ async function GET(request: Request) {
|
|||||||
mode: "insensitive",
|
mode: "insensitive",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
include: {
|
include: {
|
||||||
Voting_DaftarNamaVote: {
|
Voting_DaftarNamaVote: {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@@ -249,6 +257,8 @@ async function GET(request: Request) {
|
|||||||
mode: "insensitive",
|
mode: "insensitive",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
include: {
|
include: {
|
||||||
Voting_DaftarNamaVote: {
|
Voting_DaftarNamaVote: {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
|||||||
48
zCoba.js
48
zCoba.js
@@ -1,28 +1,26 @@
|
|||||||
// const data = [
|
const { PrismaClient } = require('@prisma/client')
|
||||||
// {
|
|
||||||
// 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 prisma = new PrismaClient()
|
||||||
|
|
||||||
console.error("errornya disini klik aja",import.meta.url);
|
async function main() {
|
||||||
console.log(new Set(data.map((d) => d.authorId)));
|
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