Merge pull request 'API Mobile Event' (#14) from mobile/15-sep-25 into staging
Reviewed-on: bip/hipmi#14
This commit is contained in:
@@ -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.
|
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.4.36](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.35...v1.4.36) (2025-09-15)
|
||||||
|
|
||||||
## [1.4.35](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.34...v1.4.35) (2025-09-12)
|
## [1.4.35](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.34...v1.4.35) (2025-09-12)
|
||||||
|
|
||||||
## [1.4.34](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.33...v1.4.34) (2025-09-01)
|
## [1.4.34](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.33...v1.4.34) (2025-09-01)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hipmi",
|
"name": "hipmi",
|
||||||
"version": "1.4.35",
|
"version": "1.4.36",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "bun prisma/seed.ts"
|
"seed": "bun prisma/seed.ts"
|
||||||
|
|||||||
48
src/app/api/mobile/event/[id]/check-participants/route.ts
Normal file
48
src/app/api/mobile/event/[id]/check-participants/route.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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 { searchParams } = new URL(request.url);
|
||||||
|
const userId = searchParams.get("userId");
|
||||||
|
|
||||||
|
let fixData
|
||||||
|
|
||||||
|
const checkParticipant = await prisma.event_Peserta.findFirst({
|
||||||
|
where: {
|
||||||
|
userId: userId as any,
|
||||||
|
eventId: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkParticipant !== null) {
|
||||||
|
fixData = true;
|
||||||
|
} else {
|
||||||
|
fixData = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Success get participants",
|
||||||
|
data: fixData,
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Error get participants",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
import { NextResponse } from "next/server";
|
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { POST , GET};
|
export { GET, POST };
|
||||||
|
|
||||||
async function POST(request: Request, { params }: { params: { id: string } }) {
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { userId } = await request.json();
|
const { userId } = await request.json();
|
||||||
|
|
||||||
|
|
||||||
const createJoin = await prisma.event_Peserta.create({
|
const createJoin = await prisma.event_Peserta.create({
|
||||||
data: {
|
data: {
|
||||||
eventId: id,
|
eventId: id,
|
||||||
@@ -49,6 +48,7 @@ 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 data = await prisma.event_Peserta.findMany({
|
const data = await prisma.event_Peserta.findMany({
|
||||||
where: {
|
where: {
|
||||||
eventId: id,
|
eventId: id,
|
||||||
@@ -63,6 +63,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
username: true,
|
username: true,
|
||||||
Profile: {
|
Profile: {
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
imageId: true,
|
imageId: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import _ from "lodash";
|
|
||||||
import { NextResponse } from "next/server";
|
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
import _ from "lodash";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export { POST, GET };
|
export { GET, POST };
|
||||||
|
|
||||||
async function POST(request: Request) {
|
async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
@@ -52,74 +52,194 @@ async function POST(request: Request) {
|
|||||||
|
|
||||||
async function GET(request: Request) {
|
async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
const allData = await prisma.event.findMany({
|
const { searchParams } = new URL(request.url);
|
||||||
where: {
|
const category = searchParams.get("category");
|
||||||
active: true,
|
const userId = searchParams.get("userId");
|
||||||
eventMaster_StatusId: "1",
|
|
||||||
isArsip: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let i of allData) {
|
console.log("[CAT]", category);
|
||||||
if (moment(i.tanggalSelesai).diff(moment(), "minutes") < 0) {
|
console.log("[USER]", userId);
|
||||||
const updateArsip = await prisma.event.update({
|
|
||||||
where: {
|
|
||||||
id: i.id,
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
isArsip: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!updateArsip) {
|
let fixData;
|
||||||
console.log("gagal update arsip");
|
|
||||||
return [];
|
if (category === "beranda") {
|
||||||
|
const allData = await prisma.event.findMany({
|
||||||
|
where: {
|
||||||
|
active: true,
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i of allData) {
|
||||||
|
if (moment(i.tanggalSelesai).diff(moment(), "minutes") < 0) {
|
||||||
|
const updateArsip = await prisma.event.update({
|
||||||
|
where: {
|
||||||
|
id: i.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isArsip: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!updateArsip) {
|
||||||
|
console.log("gagal update arsip");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const takeData = 10;
|
||||||
|
// const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
|
const data = await prisma.event.findMany({
|
||||||
|
// take: takeData,
|
||||||
|
// skip: skipData,
|
||||||
|
orderBy: [
|
||||||
|
{
|
||||||
|
tanggal: "asc",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
active: true,
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: false,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
deskripsi: true,
|
||||||
|
tanggal: true,
|
||||||
|
tanggalSelesai: true,
|
||||||
|
EventMaster_Status: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
authorId: true,
|
||||||
|
Author: {
|
||||||
|
include: {
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = data;
|
||||||
|
} else if (category === "contribution") {
|
||||||
|
const data = await prisma.event_Peserta.findMany({
|
||||||
|
where: {
|
||||||
|
userId: userId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
eventId: true,
|
||||||
|
userId: true,
|
||||||
|
Event: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
tanggal: true,
|
||||||
|
Event_Peserta: {
|
||||||
|
take: 4,
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
userId: true,
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = data;
|
||||||
|
} else if (category === "all-history") {
|
||||||
|
fixData = await prisma.event.findMany({
|
||||||
|
orderBy: {
|
||||||
|
tanggal: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
tanggal: true,
|
||||||
|
deskripsi: true,
|
||||||
|
active: true,
|
||||||
|
authorId: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (category === "my-history") {
|
||||||
|
fixData = await prisma.event.findMany({
|
||||||
|
orderBy: {
|
||||||
|
tanggal: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
authorId: userId,
|
||||||
|
eventMaster_StatusId: "1",
|
||||||
|
isArsip: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
tanggal: true,
|
||||||
|
deskripsi: true,
|
||||||
|
active: true,
|
||||||
|
authorId: true,
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// const takeData = 10;
|
|
||||||
// const skipData = page * takeData - takeData;
|
|
||||||
|
|
||||||
const data = await prisma.event.findMany({
|
|
||||||
// take: takeData,
|
|
||||||
// skip: skipData,
|
|
||||||
|
|
||||||
orderBy: [
|
|
||||||
{
|
|
||||||
tanggal: "asc",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
where: {
|
|
||||||
active: true,
|
|
||||||
eventMaster_StatusId: "1",
|
|
||||||
isArsip: false,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
title: true,
|
|
||||||
deskripsi: true,
|
|
||||||
tanggal: true,
|
|
||||||
tanggalSelesai: true,
|
|
||||||
EventMaster_Status: {
|
|
||||||
select: {
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
authorId: true,
|
|
||||||
Author: {
|
|
||||||
include: {
|
|
||||||
Profile: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
message: "Success get event",
|
message:
|
||||||
data: data,
|
category === ""
|
||||||
|
? "Success get event, but category is empty"
|
||||||
|
: "Success get event",
|
||||||
|
data: fixData,
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user