Compare commits
9 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fe5826f5c | |||
| c47decf246 | |||
| 4ef93e0509 | |||
| 3052dabbce | |||
|
|
4fc0ebf7ee | ||
|
|
577ee38220 | ||
|
|
70849ba2a9 | ||
|
|
aa8dec5391 | ||
|
|
fd09783c19 |
@@ -2,6 +2,8 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.5.6](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.5...v1.5.6) (2025-10-21)
|
||||
|
||||
## [1.5.5](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.4...v1.5.5) (2025-10-20)
|
||||
|
||||
## [1.5.4](https://wibugit.wibudev.com/bip/hipmi/compare/v1.5.3...v1.5.4) (2025-10-17)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.5",
|
||||
"version": "1.5.6",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
134
src/app/api/mobile/admin/donation/route.ts
Normal file
134
src/app/api/mobile/admin/donation/route.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const page = searchParams.get("page");
|
||||
const search = searchParams.get("search");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
console.log("[CATEGORY]", category);
|
||||
let fixData;
|
||||
|
||||
|
||||
try {
|
||||
if (category === "dashboard") {
|
||||
const publish = await prisma.donasi.count({
|
||||
where: {
|
||||
DonasiMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const review = await prisma.donasi.count({
|
||||
where: {
|
||||
DonasiMaster_Status: {
|
||||
name: "Review",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const reject = await prisma.donasi.count({
|
||||
where: {
|
||||
DonasiMaster_Status: {
|
||||
name: "Reject",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const countCategoryDonation = await prisma.donasiMaster_Kategori.findMany(
|
||||
{
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const categoryDonation = countCategoryDonation.length;
|
||||
|
||||
fixData = {
|
||||
publish,
|
||||
review,
|
||||
reject,
|
||||
categoryDonation,
|
||||
};
|
||||
} else {
|
||||
const fixCategory = _.startCase(category || "");
|
||||
|
||||
const checkStatus = await prisma.donasiMaster_StatusDonasi.findFirst({
|
||||
where: {
|
||||
name: fixCategory,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[STATUS]", checkStatus);
|
||||
|
||||
if (!checkStatus) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data donation",
|
||||
reason: "Status not found",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
fixData = await prisma.donasi.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
DonasiMaster_Status: {
|
||||
name: checkStatus.name,
|
||||
},
|
||||
active: true,
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[LIST]", fixData);
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: `Success get data donation ${category}`,
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error get data donation:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data donation",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
53
src/app/api/mobile/admin/event/[id]/participants/route.ts
Normal file
53
src/app/api/mobile/admin/event/[id]/participants/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = params;
|
||||
|
||||
const data = await prisma.event_Peserta.findMany({
|
||||
where: {
|
||||
eventId: id,
|
||||
},
|
||||
select: {
|
||||
eventId: true,
|
||||
userId: true,
|
||||
isPresent: true,
|
||||
User: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
nomor: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get participants",
|
||||
data: data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get participants",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
129
src/app/api/mobile/admin/event/[id]/route.ts
Normal file
129
src/app/api/mobile/admin/event/[id]/route.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const data = await prisma.event.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
username: true,
|
||||
nomor: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
alamat: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
EventMaster_TipeAcara: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
EventMaster_Status: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success get data event",
|
||||
data: data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get("status");
|
||||
const fixStatus = _.startCase(status as string);
|
||||
|
||||
console.log("ID", id);
|
||||
console.log("DATA", data);
|
||||
console.log("FIX STATUS", fixStatus);
|
||||
|
||||
let fixData;
|
||||
try {
|
||||
const checkStatus = await prisma.eventMaster_Status.findFirst({
|
||||
where: {
|
||||
name: fixStatus,
|
||||
},
|
||||
});
|
||||
|
||||
if (!checkStatus)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error update data event",
|
||||
reason: "Status not found",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
|
||||
if (fixStatus === "Reject") {
|
||||
const updateData = await prisma.event.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
catatan: data,
|
||||
eventMaster_StatusId: checkStatus.id,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updateData;
|
||||
} else if (fixStatus === "Publish") {
|
||||
const updateData = await prisma.event.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
eventMaster_StatusId: checkStatus.id,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updateData;
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success update data event",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to update data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
192
src/app/api/mobile/admin/event/route.ts
Normal file
192
src/app/api/mobile/admin/event/route.ts
Normal file
@@ -0,0 +1,192 @@
|
||||
import _ from "lodash";
|
||||
import { prisma } from "@/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
import moment from "moment";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
const fixStatus = _.startCase(category || "");
|
||||
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
const takeData = 10;
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
let fixData;
|
||||
|
||||
console.log("[CATEGORY]", category);
|
||||
// console.log("[FIX STATUS]", fixStatus);
|
||||
|
||||
try {
|
||||
if (category === "dashboard") {
|
||||
const publish = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
const review = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Review",
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
const reject = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Reject",
|
||||
},
|
||||
isArsip: false,
|
||||
},
|
||||
});
|
||||
|
||||
const history = await prisma.event.count({
|
||||
where: {
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isArsip: true,
|
||||
},
|
||||
});
|
||||
|
||||
const typeOfEvent = await prisma.eventMaster_TipeAcara.count({
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = {
|
||||
publish,
|
||||
review,
|
||||
reject,
|
||||
history,
|
||||
typeOfEvent,
|
||||
};
|
||||
} else if (category === "history") {
|
||||
console.log("[HISTORY HERE]");
|
||||
|
||||
const data = await prisma.event.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isArsip: true,
|
||||
EventMaster_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
} else {
|
||||
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: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
tanggal: "asc",
|
||||
},
|
||||
where: {
|
||||
active: true,
|
||||
isArsip: false,
|
||||
EventMaster_Status: {
|
||||
name: fixStatus,
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: `Success get data event ${category}`,
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(`[ERROR GET DATA EVENT: ${category}]`, error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: `Error get data event ${category}`,
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
59
src/app/api/mobile/admin/master/type-of-event/[id]/route.ts
Normal file
59
src/app/api/mobile/admin/master/type-of-event/[id]/route.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const data = await prisma.eventMaster_TipeAcara.findUnique({
|
||||
where: {
|
||||
id: Number(id),
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get type of event",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error get type of event", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get type of event",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
|
||||
try {
|
||||
const updated = await prisma.eventMaster_TipeAcara.update({
|
||||
where: {
|
||||
id: Number(id),
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
active: data.active,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success update type of event",
|
||||
data: updated,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error update type of event", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error update type of event",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
70
src/app/api/mobile/admin/master/type-of-event/route.ts
Normal file
70
src/app/api/mobile/admin/master/type-of-event/route.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
async function GET(request: Request) {
|
||||
try {
|
||||
const data = await prisma.eventMaster_TipeAcara.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Success get type of event",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error get type of event", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Error get type of event",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function POST(request: Request) {
|
||||
const { data } = await request.json();
|
||||
|
||||
try {
|
||||
const checkList = await prisma.eventMaster_TipeAcara.count({});
|
||||
|
||||
if (!checkList) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Type of event already exists",
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const created = await prisma.eventMaster_TipeAcara.create({
|
||||
data: {
|
||||
id: checkList + 1,
|
||||
name: data,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success create type of event",
|
||||
},
|
||||
{ status: 201 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error create type of event", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error create type of event",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
|
||||
export { GET };
|
||||
export { GET , PUT};
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
@@ -36,3 +37,73 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get("status");
|
||||
const fixStatus = _.startCase(status as string);
|
||||
let fixData;
|
||||
|
||||
|
||||
try {
|
||||
const checkStatus = await prisma.voting_Status.findFirst({
|
||||
where: {
|
||||
name: fixStatus,
|
||||
},
|
||||
});
|
||||
|
||||
if (!checkStatus)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error update data voting",
|
||||
reason: "Status not found",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
|
||||
if (fixStatus === "Reject") {
|
||||
const updateStatus = await prisma.voting.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
voting_StatusId: checkStatus.id,
|
||||
catatan: data,
|
||||
},
|
||||
});
|
||||
fixData = updateStatus;
|
||||
} else if (fixStatus === "Publish") {
|
||||
const updateStatus = await prisma.voting.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
voting_StatusId: checkStatus.id,
|
||||
},
|
||||
});
|
||||
fixData = updateStatus;
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success update data voting",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.log("[ERROR UPDATE DATA VOTING]", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error update data voting",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export { GET };
|
||||
|
||||
@@ -15,9 +16,6 @@ async function GET(request: Request) {
|
||||
const skipData = Number(page) * takeData - takeData;
|
||||
let fixData;
|
||||
|
||||
console.log("CATEGORY", category);
|
||||
console.log("FIX TO STATUS", fixToStatus);
|
||||
|
||||
try {
|
||||
if (category === "dashboard") {
|
||||
const publish = await prisma.voting.count({
|
||||
@@ -79,8 +77,44 @@ async function GET(request: Request) {
|
||||
history,
|
||||
};
|
||||
} else if (category === "history") {
|
||||
fixData = await prisma.voting.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
Voting_Status: {
|
||||
name: "Publish",
|
||||
},
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
akhirVote: {
|
||||
lte: new Date(),
|
||||
},
|
||||
title: {
|
||||
contains: search ? search : "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Voting_Kontributor: true,
|
||||
Voting_DaftarNamaVote: true,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
|
||||
// ====== Status Publish Start ====== //
|
||||
if (fixToStatus === "Publish") {
|
||||
const getAllData = await prisma.voting.findMany({
|
||||
|
||||
@@ -9,6 +9,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const userId = searchParams.get("userId");
|
||||
|
||||
console.log("id", id);
|
||||
console.log("userId", userId);
|
||||
|
||||
let fixData
|
||||
|
||||
const checkParticipant = await prisma.event_Peserta.findFirst({
|
||||
|
||||
168
src/app/api/mobile/event/[id]/confirmation/route.ts
Normal file
168
src/app/api/mobile/event/[id]/confirmation/route.ts
Normal file
@@ -0,0 +1,168 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const { id } = params;
|
||||
let fixData;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const userId = searchParams.get("userId");
|
||||
|
||||
const checkDataEvent = await prisma.event.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
tanggal: true,
|
||||
tanggalSelesai: true,
|
||||
lokasi: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!checkDataEvent) {
|
||||
return NextResponse.json(
|
||||
{ message: "Event Not Found", response: null },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
let peserta;
|
||||
const checkPeserta = await prisma.event_Peserta.findFirst({
|
||||
where: {
|
||||
userId: userId,
|
||||
eventId: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (checkPeserta) {
|
||||
peserta = true;
|
||||
} else {
|
||||
peserta = false;
|
||||
}
|
||||
|
||||
let kehadiran;
|
||||
const checkKehadiran = await prisma.event_Peserta.findFirst({
|
||||
where: {
|
||||
userId: userId,
|
||||
eventId: id,
|
||||
},
|
||||
select: {
|
||||
isPresent: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (checkKehadiran?.isPresent) {
|
||||
kehadiran = true;
|
||||
} else {
|
||||
kehadiran = false;
|
||||
}
|
||||
|
||||
fixData = {
|
||||
dataEvent: checkDataEvent,
|
||||
peserta: peserta,
|
||||
kehadiran: kehadiran,
|
||||
};
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: "Event Found", data: fixData },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error get confirmation event", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error get confirmation event",
|
||||
reason: (error as Error).message || error,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
let fixData;
|
||||
try {
|
||||
console.log("category", category);
|
||||
console.log("id", id);
|
||||
console.log("data", data);
|
||||
|
||||
if (category === "join_and_confirm") {
|
||||
const join = await prisma.event_Peserta.create({
|
||||
data: {
|
||||
eventId: id,
|
||||
userId: data.userId,
|
||||
isPresent: true,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = join;
|
||||
} else if (category === "confirmation") {
|
||||
const checkPeserta = await prisma.event_Peserta.findFirst({
|
||||
where: {
|
||||
userId: data.userId,
|
||||
eventId: id,
|
||||
isPresent: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (!checkPeserta) {
|
||||
return NextResponse.json(
|
||||
{ message: "Peserta Not Found", response: null },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const confirm = await prisma.event_Peserta.update({
|
||||
where: {
|
||||
id: checkPeserta.id,
|
||||
},
|
||||
data: {
|
||||
isPresent: true,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = confirm;
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: true, message: `Success ${category}`, data: fixData },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error upsert confirmation event", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Error upsert confirmation event",
|
||||
reason: (error as Error).message || error,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user