Merge pull request #166 from bipproduction/event/main

Fix event & auth
This commit is contained in:
Bagasbanuna02
2024-12-08 17:16:52 +08:00
committed by GitHub
16 changed files with 121 additions and 167 deletions

View File

@@ -1,10 +1,12 @@
import { prisma } from "@/app/lib";
import { data } from "autoprefixer";
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const id = searchParams.get("id");
export async function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id");
// const { searchParams } = new URL(request.url);
// const id = searchParams.get("id");
try {
const data = await prisma.kodeOtp.findFirst({
@@ -12,10 +14,10 @@ export async function GET(request: Request) {
id: id as string,
},
});
return new Response(JSON.stringify({ data }), { status: 200 });
return NextResponse.json(data, { status: 200 });
} catch (error) {
console.log(error);
}
return new Response(JSON.stringify({ data: null }), { status: 404 });
return NextResponse.json(null, { status: 500 });
}

View File

@@ -18,14 +18,11 @@ export async function POST(req: Request) {
const sendWa = await res.json();
if (sendWa.status !== "success")
return new Response(
JSON.stringify({
success: false,
message: "Nomor Whatsapp Tidak Aktif",
}),
return NextResponse.json(
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
{ status: 400 }
);
const createOtpId = await prisma.kodeOtp.create({
data: {
nomor: nomor,
@@ -34,32 +31,30 @@ export async function POST(req: Request) {
});
if (!createOtpId)
return new Response(
JSON.stringify({
success: false,
message: "Gagal Membuat Kode OTP",
}),
return NextResponse.json(
{ success: false, message: "Gagal Membuat Kode OTP" },
{ status: 400 }
);
return new Response(
JSON.stringify({
return NextResponse.json(
{
success: true,
message: "Kode Verifikasi Dikirim",
kodeId: createOtpId.id,
}),
},
{ status: 200 }
);
} catch (error) {
console.log(error);
return new Response(
JSON.stringify({
success: false,
message: "Server Whatsapp Error !!",
}),
return NextResponse.json(
{ success: false, message: "Server Whatsapp Error !! " },
{ status: 500 }
);
}
}
return NextResponse.json({ success: false });
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -1,28 +1,21 @@
import { prisma } from "@/app/lib";
import { cookies } from "next/headers";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const id = searchParams.get("id");
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id");
// const { searchParams } = new URL(request.url);
// const id = searchParams.get("id");
const delToken = await prisma.userSession.delete({
where: {
userId: id as string,
},
});
const delToken = await prisma.userSession.delete({
where: {
userId: id as string,
},
});
const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
return new Response(JSON.stringify({ success: true, message: "Logout Berhasil" }), {status: 200});
}
// import { cookies } from "next/headers";
// import { NextResponse } from "next/server";
// export async function GET() {
// cookies().set({
// name: "mySession",
// value: "",
// maxAge: 0,
// });
// return NextResponse.json({ status: 200, message: "Logout" });
// }
return NextResponse.json(
{ success: true, message: "Logout Berhasil" },
{ status: 200 }
);
}

View File

@@ -1,5 +1,6 @@
import { sessionCreate } from "@/app/auth/_lib/session_create";
import prisma from "@/app/lib/prisma";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
if (req.method === "POST") {
@@ -12,11 +13,8 @@ export async function POST(req: Request) {
});
if (cekUsername)
return new Response(
JSON.stringify({
success: false,
message: "Username sudah digunakan",
}),
return NextResponse.json(
{ success: false, message: "Username sudah digunakan" },
{ status: 400 }
);
@@ -43,28 +41,22 @@ export async function POST(req: Request) {
});
if (!createUserSession)
return new Response(
JSON.stringify({
success: false,
message: "Gagal Membuat Session",
}),
return NextResponse.json(
{ success: false, message: "Gagal Membuat Session" },
{ status: 400 }
);
} catch (error) {
console.log(error);
}
return new Response(
JSON.stringify({
success: true,
message: "Berhasil Login",
}),
return NextResponse.json(
{ success: true, message: "Berhasil Login", data: createUser },
{ status: 200 }
);
}
return new Response(
JSON.stringify({ success: false, message: "Method Not Allowed" }),
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -18,11 +18,11 @@ export async function POST(req: Request) {
const sendWa = await res.json();
if (sendWa.status !== "success")
return new Response(
JSON.stringify({
return NextResponse.json(
{
success: false,
message: "Nomor Whatsapp Tidak Aktif",
}),
},
{ status: 400 }
);
@@ -34,32 +34,36 @@ export async function POST(req: Request) {
});
if (!createOtpId)
return new Response(
JSON.stringify({
return NextResponse.json(
{
success: false,
message: "Gagal Membuat Kode OTP",
}),
},
{ status: 400 }
);
return new Response(
JSON.stringify({
return NextResponse.json(
{
success: true,
message: "Kode Verifikasi Dikirim",
kodeId: createOtpId.id,
}),
},
{ status: 200 }
);
} catch (error) {
console.log(error);
return new Response(
JSON.stringify({
return NextResponse.json(
{
success: false,
message: "Server Whatsapp Error !!",
}),
},
{ status: 500 }
);
}
}
return NextResponse.json({ success: false });
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -1,9 +1,5 @@
import { sessionCreate } from "@/app/auth/_lib/session_create";
import prisma from "@/app/lib/prisma";
import { ServerEnv } from "@/app/lib/server_env";
import { sealData } from "iron-session";
import { revalidatePath } from "next/cache";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
@@ -23,10 +19,9 @@ export async function POST(req: Request) {
},
});
if (dataUser === null)
return new Response(
JSON.stringify({ success: false, message: "Nomor Belum Terdaftar" }),
return NextResponse.json(
{ success: false, message: "Nomor Belum Terdaftar" },
{ status: 404 }
);
@@ -59,49 +54,27 @@ export async function POST(req: Request) {
});
if (!createUserSession)
return new Response(
JSON.stringify({ success: false, message: "Gagal Membuat Session" }),
return NextResponse.json(
{ success: false, message: "Gagal Membuat Session" },
{ status: 400 }
);
} catch (error) {
console.log(error);
}
// if (data) {
// const res = await sealData(
// JSON.stringify({
// id: data.id,
// username: data.username,
// }),
// {
// password: ServerEnv.value?.WIBU_PWD as string,
// }
// );
// cookies().set({
// name: "mySession",
// value: res,
// maxAge: 60 * 60 * 24 * 7,
// });
// revalidatePath("/dev/home");
// return NextResponse.json({ status: 200, data });
// }
// return NextResponse.json({ success: true });
return new Response(
JSON.stringify({
return NextResponse.json(
{
success: true,
message: "Berhasil Login",
roleId: dataUser.masterUserRoleId,
active: dataUser.active,
}),
},
{ status: 200 }
);
}
return new Response(
JSON.stringify({ success: false, message: "Method Not Allowed" }),
return NextResponse.json(
{ success: false, message: "Method Not Allowed" },
{ status: 405 }
);
}

View File

@@ -8,7 +8,7 @@ export async function GET(req: Request) {
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
return NextResponse.json({ success: false });
// return new Response(JSON.stringify({ success: false }));
}
return NextResponse.json({ success: true });
}

View File

@@ -1,4 +1,5 @@
import { event_newGetListPesertaById } from "@/app_modules/event/fun";
import { Event_getListPesertaById } from "@/app_modules/event/fun/get/get_list_peserta_by_id";
import { toNumber } from "lodash";
import { NextResponse } from "next/server";

View File

@@ -1,6 +1,7 @@
import { headers } from "next/headers";
import { NextResponse } from "next/server";
export async function GET(req: Request) {
const origin = new URL(req.url).origin;
return new Response(JSON.stringify({ success: true, origin }));
return NextResponse.json({ success: true, origin });
}

View File

@@ -1,8 +1,11 @@
import prisma from "@/app/lib/prisma";
import { NextResponse } from "next/server";
export async function GET(req: Request) {
const page = new URL(req.url).searchParams.get("page");
if (!page) return new Response("page require", { status: 400 });
if (!page)
return NextResponse.json({ message: "Page not found" }, { status: 400 });
const res = await prisma.projectCollaboration_Message.findMany({
take: 5,
skip: +page * 5 - 5,

View File

@@ -1,7 +1,9 @@
import { NextResponse } from "next/server";
export async function GET(req: Request) {
const auth = req.headers.get("Authorization");
const token = auth?.split(" ")[1];
if (!token)
return new Response(JSON.stringify({ success: false }), { status: 401 });
return new Response(JSON.stringify({ success: true }));
if (!token) return NextResponse.json({ success: false }, { status: 401 });
return NextResponse.json({ success: true });
}

View File

@@ -1,7 +1,8 @@
import { headers } from "next/headers";
import { NextResponse } from "next/server";
export async function GET(
req: Request) {
const origin = new URL(req.url).origin;
return new Response(JSON.stringify({ success: true, origin }));
return NextResponse.json({ success: true, origin });
}

View File

@@ -1,5 +1,6 @@
import { prisma } from "@/app/lib";
import { sessionCreate } from "../../_lib/session_create";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
const user = await prisma.user.findUnique({
@@ -12,10 +13,7 @@ export async function POST(req: Request) {
},
});
if (!user)
return new Response(
JSON.stringify({ success: false, message: "User not found" }), {status: 404}
);
if (!user) return NextResponse.json({ success: false }, { status: 404 });
const token = await sessionCreate({
sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
@@ -23,5 +21,5 @@ export async function POST(req: Request) {
user: user as any,
});
return new Response(JSON.stringify({ success: true, token }));
return NextResponse.json({ success: true, token });
}

View File

@@ -1,5 +1,8 @@
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export async function GET() {
const del = cookies().delete(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
return new Response(JSON.stringify({ success: true }));
return NextResponse.json({ success: true, message: "Logout Berhasil" });
}

View File

@@ -1,10 +1,5 @@
import { newFunGetUserId } from "@/app/lib/new_fun_user_id";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import Ui_Konfirmasi from "@/app_modules/event/_ui/konfirmasi";
import { event_funCheckPesertaByUserId } from "@/app_modules/event/fun";
import { event_getOneById } from "@/app_modules/event/fun/get/get_one_by_id";
import moment from "moment";
import { redirect } from "next/navigation";
export default async function Page({
params,

View File

@@ -1,38 +1,33 @@
"use client";
import {
UIGlobal_LayoutDefault,
UIGlobal_LayoutTamplate,
} from "@/app_modules/_global/ui";
import {
Button,
Card,
Center,
Group,
Paper,
Skeleton,
Stack,
Text,
Title,
} from "@mantine/core";
import { MODEL_EVENT } from "../model/interface";
import { useShallowEffect } from "@mantine/hooks";
import { AccentColor, MainColor } from "@/app_modules/_global/color";
import { event_funCheckKehadiran, event_funUpdateKehadiran } from "../fun";
import { API_RouteEvent } from "@/app/lib/api_user_router/route_api_event";
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
import { MainColor } from "@/app_modules/_global/color";
import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
import {
ComponentGlobal_NotifikasiBerhasil,
ComponentGlobal_NotifikasiGagal,
} from "@/app_modules/_global/notif_global";
import { redirect, useRouter } from "next/navigation";
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
import { useState } from "react";
import { API_RouteEvent } from "@/app/lib/api_user_router/route_api_event";
import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
import moment from "moment";
import { gs_event_hotMenu } from "../global_state";
import {
UIGlobal_LayoutDefault
} from "@/app_modules/_global/ui";
import {
Button,
Center,
Group,
Skeleton,
Stack,
Text
} from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useAtom } from "jotai";
import { Event_funJoinEvent } from "../fun/create/fun_join_event";
import moment from "moment";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { event_funUpdateKehadiran } from "../fun";
import { Event_funJoinAndConfirmEvent } from "../fun/create/fun_join_and_confirm";
import { gs_event_hotMenu } from "../global_state";
import { MODEL_EVENT } from "../model/interface";
export default function Ui_Konfirmasi({
userLoginId,
@@ -70,7 +65,6 @@ export default function Ui_Konfirmasi({
API_RouteEvent.check_peserta({ eventId: eventId, userId: userLoginId })
);
const data = await res.json();
console.log("cek peserta", data);
setIsJoin(data);
}
@@ -87,9 +81,6 @@ export default function Ui_Konfirmasi({
setIsPresent(data);
}
// console.log("kehadiran:", isPresent);
// console.log("data:", data);
if (data == null && isPresent == null) {
return <SkeletonIsDataNull />;
}
@@ -102,7 +93,7 @@ export default function Ui_Konfirmasi({
);
}
if (moment(data?.tanggal).diff(moment(), "minute") < 0) {
if (moment(data?.tanggalSelesai).diff(moment(), "minute") < 0) {
return (
<>
<EventAlreadyDone title={data?.title} eventId={eventId} />