Merge pull request 'API Profile' (#3) from mobile/25-aug-25 into staging

Reviewed-on: bip/hipmi#3
This commit is contained in:
2025-08-25 17:05:55 +08:00
5 changed files with 111 additions and 4 deletions

View File

@@ -2,6 +2,13 @@
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.29](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.28...v1.4.29) (2025-08-25)
### Bug Fixes
* test new github ([555b6e7](https://wibugit.wibudev.com/bip/hipmi/commit/555b6e76332d867fc72b51cc1163fd6911a63288))
## [1.4.28](https://github.com/bipproduction/hipmi/compare/v1.4.27...v1.4.28) (2025-06-16)
## [1.4.27](https://github.com/bipproduction/hipmi/compare/v1.4.26...v1.4.27) (2025-06-16)

View File

@@ -1,11 +1,11 @@
{
"name": "hipmi",
"version": "1.4.28",
"version": "1.4.29",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"
},
"scripts": {
"scripts": {
"dev": "next dev --experimental-https",
"build": "next build",
"build:dev": "next build",

View File

@@ -0,0 +1,100 @@
import { prisma } from "@/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export { GET, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
let fixData;
const { id } = params;
fixData = await prisma.profile.findFirst({
where: {
id: id,
},
include: {
User: true,
},
});
return NextResponse.json(
{
success: true,
message: "Success get profile",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get profile", error);
return NextResponse.json(
{
success: false,
message: "Error get profile",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
if (request.method !== "PUT") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try {
const { id } = params;
const body = await request.json();
const { data } = body;
const cekEmail = await prisma.profile.findUnique({
where: {
email: data.email,
},
});
if (cekEmail && cekEmail.id != id)
return NextResponse.json({
success: false,
message: "Email sudah digunakan",
});
const updateData = await prisma.profile.update({
where: {
id: id,
},
data: {
name: data.name,
email: data.email,
alamat: data.alamat,
jenisKelamin: data.jenisKelamin,
},
});
if (!updateData) {
return NextResponse.json({ success: false, message: "Gagal update" });
}
return NextResponse.json({
success: true,
message: "Berhasil edit profile",
});
} catch (error) {
backendLogger.error("Error edit profile", error);
return NextResponse.json(
{
success: false,
message: "Error edit profile",
reason: (error as Error).message,
},
{ status: 500 }
);
} finally {
await prisma.$disconnect();
}
}

View File

@@ -21,8 +21,6 @@ async function POST(request: Request) {
});
}
console.log("data", data);
const create = await prisma.profile.create({
data: {
userId: data.id,

View File

@@ -59,6 +59,8 @@ export const middleware = async (req: NextRequest) => {
const { pathname } = req.nextUrl;
const apiBaseUrl = new URL(req.url).origin || process.env.NEXT_PUBLIC_API_URL;
const dbUrl = process.env.DATABASE_URL;
console.log("DATABASE_URL >>", dbUrl);
// Handle CORS preflight
const corsResponse = handleCors(req);