API Mobile

Add:
- event
- user[id]
- mobile ( api baru untuk cek token )

Fix:
- portofolio/[id]
- mobile/user

### No Issue
This commit is contained in:
2025-09-10 17:47:48 +08:00
parent af7f4e0027
commit f337d45e5c
5 changed files with 292 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export async function GET(
request: Request,
{ params }: { params: { id: string } }
) {
try {
const { id } = params;
const data = await prisma.user.findUnique({
where: {
id: id,
},
include: {
Profile: true,
},
});
return NextResponse.json(
{ success: true, message: "Berhasil mendapatkan data", data: data },
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Error get data from API ",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -1,21 +1,45 @@
import { decrypt } from "@/app/(auth)/_lib/decrypt";
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
const token = searchParams.get("token");
const search = searchParams.get("search");
const dataUser = await decrypt({
token: token!,
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
});
const id = dataUser?.id;
const user = await prisma.user.findUnique({
const data = await prisma.user.findMany({
orderBy: {
username: "asc",
},
where: {
id: id as string,
username: {
contains: search || "",
mode: "insensitive",
},
active: true,
NOT: {
Profile: null,
},
OR: [
{
MasterUserRole: {
name: "User",
},
},
{
MasterUserRole: {
name: "Admin",
},
},
],
},
include: {
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
});
@@ -23,7 +47,7 @@ export async function GET(request: Request) {
{
success: true,
message: "Berhasil mendapatkan data",
data: user,
data: data,
},
{
status: 200,
@@ -40,7 +64,46 @@ export async function GET(request: Request) {
status: 500,
}
);
} finally {
await prisma.$disconnect();
}
// try {
// const { searchParams } = new URL(request.url);
// const token = searchParams.get("token");
// const dataUser = await decrypt({
// token: token!,
// encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
// });
// const id = dataUser?.id;
// const user = await prisma.user.findUnique({
// where: {
// id: id as string,
// },
// });
// return NextResponse.json(
// {
// success: true,
// message: "Berhasil mendapatkan data",
// data: user,
// },
// {
// status: 200,
// }
// );
// } catch (error) {
// return NextResponse.json(
// {
// success: false,
// message: "Gagal mendapatkan data",
// reason: (error as Error).message,
// },
// {
// status: 500,
// }
// );
// } finally {
// await prisma.$disconnect();
// }
}