Merge pull request 'Portofolio Mobile API' (#9) from mobile/1-sep-25 into staging

Reviewed-on: bip/hipmi#9
This commit is contained in:
2025-09-01 17:15:59 +08:00
5 changed files with 240 additions and 12 deletions

View File

@@ -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.
## [1.4.34](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.33...v1.4.34) (2025-09-01)
## [1.4.33](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.32...v1.4.33) (2025-08-29)
## [1.4.32](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.31...v1.4.32) (2025-08-29)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.4.33",
"version": "1.4.34",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

View File

@@ -0,0 +1,41 @@
import { NextResponse } from "next/server";
export { DELETE };
async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
try {
const { id } = params;
const deleteFile = await fetch(
`https://wibu-storage.wibudev.com/api/files/${id}/delete`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
}
);
if (deleteFile.ok) {
return NextResponse.json(
{
success: true,
message: "File berhasil dihapus",
},
{ status: 200 }
);
}
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Gagal menghapus file, coba lagi nanti (error: 500)",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -2,15 +2,9 @@ import { funGetDirectoryNameByValue } from "@/app_modules/_global/fun/get";
import { NextResponse } from "next/server";
export async function POST(request: Request) {
const contentType = request.headers.get("content-type");
console.log("Incoming Content-Type:", contentType);
const formData = await request.formData();
const file: any = formData.get("file");
const dirId = formData.get("dirId");
console.log("formData >>", formData);
const keyOfDirectory = await funGetDirectoryNameByValue({
value: dirId as string,
});
@@ -27,11 +21,12 @@ export async function POST(request: Request) {
const dataRes = await res.json();
if (res.ok) {
console.log(
`Success upload ${keyOfDirectory}: ${JSON.stringify(dataRes.data, null, 2)}`
);
return NextResponse.json(
{ success: true, data: dataRes.data },
{
success: true,
data: dataRes.data,
message: "Success upload file " + keyOfDirectory,
},
{ status: 200 }
);
} else {

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
export { GET };
export { GET, DELETE, PUT };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
@@ -50,3 +50,193 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
);
}
}
async function DELETE(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params;
const data = await prisma.portofolio.findUnique({
where: {
id: id,
},
include: {
BusinessMaps: {
select: {
pinId: true,
imageId: true,
},
},
},
});
try {
if (data?.logoId != null) {
const id = data?.logoId;
const deleteLogo = await fetch(
`https://wibu-storage.wibudev.com/api/files/${id}/delete`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
}
);
if (deleteLogo.ok) {
console.log("Success delete logo");
}
}
if (data?.BusinessMaps?.pinId != null) {
const pinId = data?.BusinessMaps?.pinId;
const deletePin = await fetch(
`https://wibu-storage.wibudev.com/api/files/${pinId}/delete`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
}
);
if (deletePin.ok) {
console.log(`Success delete pin`);
}
const imageId = data?.BusinessMaps?.imageId;
const deleteImage = await fetch(
`https://wibu-storage.wibudev.com/api/files/${imageId}/delete`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
}
);
if (deleteImage.ok) {
console.log(`Success delete image`);
}
}
} catch (error) {
console.error("Error delete logo", error);
}
const deletePortoMedsos = await prisma.portofolio_MediaSosial.delete({
where: {
portofolioId: id,
},
});
// const deleteMap = await prisma.businessMaps.delete({
// where: {
// portofolioId: id,
// },
// });
// console.log("DELETE PORTOFOLIO MEDSOS >>", deletePortoMedsos);
const deletePortofolio = await prisma.portofolio.delete({
where: {
id: id,
},
});
return NextResponse.json(
{ success: true, message: "Berhasil menghapus data" },
{ status: 200 }
);
} catch (error) {
console.error(error);
return NextResponse.json(
{
success: false,
message: "Gagal menghapus data, coba lagi nanti (error: 500)",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}
async function PUT(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const { data } = await request.json();
const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
let message;
if (category === "detail") {
const updateDetail = await prisma.portofolio.update({
where: { id },
data: {
namaBisnis: data.namaBisnis,
alamatKantor: data.alamatKantor,
tlpn: data.tlpn,
deskripsi: data.deskripsi,
masterBidangBisnisId: data.masterBidangBisnisId,
},
});
if (!updateDetail) {
return NextResponse.json({
success: false,
message: "Gagal mengupdate detail portofolio",
});
}
message = "Berhasil mengupdate detail portofolio";
} else if (category === "medsos") {
const updateMedsos = await prisma.portofolio_MediaSosial.update({
where: { portofolioId: id },
data: {
facebook: data.facebook,
instagram: data.instagram,
tiktok: data.tiktok,
twitter: data.twitter,
youtube: data.youtube,
},
});
if (!updateMedsos) {
return NextResponse.json({
success: false,
message: "Gagal mengupdate medsos portofolio",
});
}
message = "Berhasil mengupdate medsos portofolio";
} else if (category === "logo") {
const updateLogo = await prisma.portofolio.update({
where: { id },
data: {
logoId: data.fileId,
},
});
if (!updateLogo) {
return NextResponse.json({
success: false,
message: "Gagal mengupdate logo portofolio",
});
}
message = "Berhasil mengupdate logo portofolio";
}
return NextResponse.json(
{
success: true,
message: message,
},
{ status: 200 }
);
} catch (error) {
console.error("Error update data portofolio", error);
return NextResponse.json(
{
success: false,
message: "Gagal mengupdate data, coba lagi nanti (error: 500)",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}