Compare commits
6 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fe5826f5c | |||
| c47decf246 | |||
| 4ef93e0509 | |||
| 3052dabbce | |||
|
|
4fc0ebf7ee | ||
|
|
577ee38220 |
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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,6 @@ export async function GET(
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const userId = searchParams.get("userId");
|
const userId = searchParams.get("userId");
|
||||||
|
|
||||||
console.log("userId", userId);
|
|
||||||
|
|
||||||
const checkDataEvent = await prisma.event.findUnique({
|
const checkDataEvent = await prisma.event.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
@@ -53,8 +51,6 @@ export async function GET(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("checkPeserta", checkPeserta);
|
|
||||||
|
|
||||||
if (checkPeserta) {
|
if (checkPeserta) {
|
||||||
peserta = true;
|
peserta = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -116,33 +112,6 @@ export async function POST(
|
|||||||
console.log("id", id);
|
console.log("id", id);
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
|
|
||||||
// const checkEvent = await prisma.event.findUnique({
|
|
||||||
// where: {
|
|
||||||
// id: id,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (!checkEvent) {
|
|
||||||
// return NextResponse.json(
|
|
||||||
// { message: "Event Not Found", response: null },
|
|
||||||
// { status: 400 }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const checkPeserta = await prisma.event_Peserta.findFirst({
|
|
||||||
// where: {
|
|
||||||
// userId: userId,
|
|
||||||
// eventId: id,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (!checkPeserta) {
|
|
||||||
// return NextResponse.json(
|
|
||||||
// { message: "Peserta Not Found", response: null },
|
|
||||||
// { status: 400 }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (category === "join_and_confirm") {
|
if (category === "join_and_confirm") {
|
||||||
const join = await prisma.event_Peserta.create({
|
const join = await prisma.event_Peserta.create({
|
||||||
data: {
|
data: {
|
||||||
@@ -152,14 +121,13 @@ export async function POST(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("join", join);
|
|
||||||
fixData = join;
|
fixData = join;
|
||||||
} else if (category === "confirmation") {
|
} else if (category === "confirmation") {
|
||||||
const checkPeserta = await prisma.event_Peserta.findFirst({
|
const checkPeserta = await prisma.event_Peserta.findFirst({
|
||||||
where: {
|
where: {
|
||||||
userId: data.userId,
|
userId: data.userId,
|
||||||
eventId: id,
|
eventId: id,
|
||||||
isPresent: true,
|
isPresent: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,7 +147,6 @@ export async function POST(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("confirm", confirm);
|
|
||||||
fixData = confirm;
|
fixData = confirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user