Merge pull request 'API Profile' (#3) from mobile/25-aug-25 into staging
Reviewed-on: bip/hipmi#3
This commit is contained in:
@@ -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.
|
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.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)
|
## [1.4.27](https://github.com/bipproduction/hipmi/compare/v1.4.26...v1.4.27) (2025-06-16)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "hipmi",
|
"name": "hipmi",
|
||||||
"version": "1.4.28",
|
"version": "1.4.29",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "bun prisma/seed.ts"
|
"seed": "bun prisma/seed.ts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --experimental-https",
|
"dev": "next dev --experimental-https",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"build:dev": "next build",
|
"build:dev": "next build",
|
||||||
|
|||||||
100
src/app/api/mobile/profile/[id]/route.ts
Normal file
100
src/app/api/mobile/profile/[id]/route.ts
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,8 +21,6 @@ async function POST(request: Request) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("data", data);
|
|
||||||
|
|
||||||
const create = await prisma.profile.create({
|
const create = await prisma.profile.create({
|
||||||
data: {
|
data: {
|
||||||
userId: data.id,
|
userId: data.id,
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
const { pathname } = req.nextUrl;
|
const { pathname } = req.nextUrl;
|
||||||
|
|
||||||
const apiBaseUrl = new URL(req.url).origin || process.env.NEXT_PUBLIC_API_URL;
|
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
|
// Handle CORS preflight
|
||||||
const corsResponse = handleCors(req);
|
const corsResponse = handleCors(req);
|
||||||
|
|||||||
Reference in New Issue
Block a user