Merge pull request #261 from bipproduction/bagas/31-jan-25
fix event admin
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
@@ -19,7 +20,7 @@ export async function GET(
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 1;
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
try {
|
||||
@@ -29,7 +30,7 @@ export async function GET(
|
||||
if (!page && !search) {
|
||||
fixData = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
@@ -38,11 +39,26 @@ export async function GET(
|
||||
name: fixStatus,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
} else if (!page && search) {
|
||||
fixData = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
@@ -55,13 +71,53 @@ export async function GET(
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
} else if (page && !search) {
|
||||
if (fixStatus === "Publish") {
|
||||
const getAllData = await prisma.event.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
EventMaster_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of getAllData) {
|
||||
if (moment(i.tanggalSelesai).diff(moment(), "minutes") < 0) {
|
||||
await prisma.event.update({
|
||||
where: {
|
||||
id: i.id,
|
||||
},
|
||||
data: {
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
@@ -70,12 +126,29 @@ export async function GET(
|
||||
name: fixStatus,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
@@ -85,11 +158,36 @@ export async function GET(
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
} else if (page && search) {
|
||||
if (fixStatus === "Publish") {
|
||||
const getAllData = await prisma.event.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
EventMaster_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of getAllData) {
|
||||
if (moment(i.tanggalSelesai).diff(moment(), "minutes") < 0) {
|
||||
await prisma.event.update({
|
||||
where: {
|
||||
id: i.id,
|
||||
},
|
||||
data: {
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
@@ -102,12 +200,26 @@ export async function GET(
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.event.count({
|
||||
where: {
|
||||
active: true,
|
||||
eventMaster_StatusId: "1",
|
||||
isArsip: false,
|
||||
title: {
|
||||
contains: search,
|
||||
|
||||
201
src/app/api/admin/event/riwayat/route.ts
Normal file
201
src/app/api/admin/event/riwayat/route.ts
Normal file
@@ -0,0 +1,201 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
|
||||
if (!page && !search) {
|
||||
fixData = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
} else if (!page && search) {
|
||||
fixData = await prisma.event.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
title: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
} else if (page && !search) {
|
||||
const data = await prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.event.count({
|
||||
where: {
|
||||
active: true,
|
||||
isArsip: true,
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data: data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
} else if (page && search) {
|
||||
const data = await prisma.event.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
title: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
EventMaster_TipeAcara: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nCount = await prisma.event.count({
|
||||
where: {
|
||||
active: true,
|
||||
isArsip: true,
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
data,
|
||||
nPage: _.ceil(nCount / takeData),
|
||||
};
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get data riwayat event",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error get data riwayat event >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get data riwayat event",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
export {
|
||||
apiGetEventStatusCountDashboard,
|
||||
apiGetEventTipeAcara,
|
||||
apiGetEventRiwayatCount,
|
||||
apiGetDataEventByStatus,
|
||||
apiGetAdminEventStatusCountDashboard as apiGetEventStatusCountDashboard,
|
||||
apiGetAdminEventCountTipeAcara as apiGetEventTipeAcara,
|
||||
apiGetAdminEventRiwayatCount as apiGetEventRiwayatCount,
|
||||
apiGetAdminEventByStatus as apiGetDataEventByStatus,
|
||||
apiGetAdminEventRiwayat,
|
||||
};
|
||||
|
||||
const apiGetEventStatusCountDashboard = async ({
|
||||
const apiGetAdminEventStatusCountDashboard = async ({
|
||||
name,
|
||||
}: {
|
||||
name: "Publish" | "Review" | "Reject";
|
||||
@@ -26,7 +27,7 @@ const apiGetEventStatusCountDashboard = async ({
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetEventRiwayatCount = async () => {
|
||||
const apiGetAdminEventRiwayatCount = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
@@ -43,7 +44,7 @@ const apiGetEventRiwayatCount = async () => {
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetEventTipeAcara = async () => {
|
||||
const apiGetAdminEventCountTipeAcara = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
@@ -60,7 +61,7 @@ const apiGetEventTipeAcara = async () => {
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetDataEventByStatus = async ({
|
||||
const apiGetAdminEventByStatus = async ({
|
||||
status,
|
||||
page,
|
||||
search,
|
||||
@@ -74,7 +75,35 @@ const apiGetDataEventByStatus = async ({
|
||||
|
||||
const isPage = page ? `?page=${page}` : "";
|
||||
const isSearch = search ? `&search=${search}` : "";
|
||||
const respone = await fetch(`/api/admin/event/${status}${isPage}${isSearch}`, {
|
||||
const respone = await fetch(
|
||||
`/api/admin/event/${status}${isPage}${isSearch}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return await respone.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetAdminEventRiwayat = async ({
|
||||
page,
|
||||
search,
|
||||
}: {
|
||||
page: string;
|
||||
search: string;
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const isPage = page ? `?page=${page}` : "";
|
||||
const isSearch = search ? `&search=${search}` : "";
|
||||
const response = await fetch(`/api/admin/event/riwayat${isPage}${isSearch}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
@@ -83,5 +112,5 @@ const apiGetDataEventByStatus = async ({
|
||||
},
|
||||
});
|
||||
|
||||
return await respone.json().catch(() => null);
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -2,11 +2,11 @@ import { AdminEvent_Riwayat } from "@/app_modules/admin/event";
|
||||
import { adminEvent_funGetListAllRiwayat } from "@/app_modules/admin/event/fun/get/get_list_all_riwayat";
|
||||
|
||||
export default async function Page() {
|
||||
const listRiwayat = await adminEvent_funGetListAllRiwayat({ page: 1 });
|
||||
// const listRiwayat = await adminEvent_funGetListAllRiwayat({ page: 1 });
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminEvent_Riwayat listRiwayat={listRiwayat} />
|
||||
<AdminEvent_Riwayat />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { AdminEvent_TablePublish } from "@/app_modules/admin/event";
|
||||
import { adminEvent_funGetListPublish } from "@/app_modules/admin/event/fun";
|
||||
|
||||
async function Page() {
|
||||
return (
|
||||
|
||||
@@ -2,11 +2,10 @@ import { AdminEvent_TableReject } from "@/app_modules/admin/event";
|
||||
import { adminEvent_funGetListReject } from "@/app_modules/admin/event/fun";
|
||||
|
||||
export default async function Page() {
|
||||
const listReject = await adminEvent_funGetListReject({ page: 1 });
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminEvent_TableReject listReject={listReject as any} />
|
||||
<AdminEvent_TableReject />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { AdminEvent_TableReview } from "@/app_modules/admin/event";
|
||||
import { adminEvent_funGetListReview } from "@/app_modules/admin/event/fun";
|
||||
|
||||
export default async function Page() {
|
||||
const listReview = await adminEvent_funGetListReview({ page: 1 });
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminEvent_TableReview listData={listReview as any} />
|
||||
<AdminEvent_TableReview />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user