Compare commits
1 Commits
mobile-api
...
mobile-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b378e8ab0 |
107
src/app/api/mobile/maps/[id]/route.ts
Normal file
107
src/app/api/mobile/maps/[id]/route.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export { GET };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
try {
|
||||
const data = await prisma.businessMaps.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data pin map",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[ERROR]", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data pin map",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
|
||||
const ceheckData = await prisma.businessMaps.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!ceheckData) {
|
||||
return NextResponse.json({
|
||||
status: 404,
|
||||
success: false,
|
||||
message: "Data tidak ditemukan",
|
||||
});
|
||||
}
|
||||
|
||||
if (data.newImageId) {
|
||||
const updated = await prisma.businessMaps.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
namePin: data.namePin,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
imageId: data.newImageId,
|
||||
},
|
||||
});
|
||||
|
||||
if (updated) {
|
||||
const deleteImage = await fetch(
|
||||
`https://wibu-storage.wibudev.com/api/files/${ceheckData.imageId}/delete`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
fixData = updated;
|
||||
} else {
|
||||
const updated = await prisma.businessMaps.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
namePin: data.namePin,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updated;
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mengupdate data pin map",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[ERROR]", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal mengupdate data pin map",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
73
src/app/api/mobile/maps/route.ts
Normal file
73
src/app/api/mobile/maps/route.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export { POST };
|
||||
|
||||
async function POST(request: Request) {
|
||||
const { data } = await request.json();
|
||||
|
||||
try {
|
||||
const created = await prisma.businessMaps.create({
|
||||
data: {
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
namePin: data.namePin,
|
||||
imageId: data.imageId || null,
|
||||
portofolioId: data.portofolioId,
|
||||
authorId: data.authorId,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil membuat pin map",
|
||||
data: created,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[ERROR]", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal membuat pin map",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const data = await prisma.businessMaps.findMany({
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
include: {
|
||||
Portofolio: {
|
||||
select: {
|
||||
id: true,
|
||||
namaBisnis: true,
|
||||
logoId: true,
|
||||
alamatKantor: true,
|
||||
tlpn: true,
|
||||
MasterBidangBisnis: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data pin map",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[ERROR]", error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data pin map",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,16 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
},
|
||||
},
|
||||
BusinessMaps: {
|
||||
select: {
|
||||
id: true,
|
||||
namePin: true,
|
||||
latitude: true,
|
||||
longitude: true,
|
||||
imageId: true,
|
||||
pinId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -98,6 +108,7 @@ async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
include: {
|
||||
BusinessMaps: {
|
||||
select: {
|
||||
id: true,
|
||||
pinId: true,
|
||||
imageId: true,
|
||||
},
|
||||
@@ -123,61 +134,66 @@ async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||
}
|
||||
}
|
||||
|
||||
if (data?.BusinessMaps?.pinId != null) {
|
||||
if (data?.BusinessMaps) {
|
||||
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`);
|
||||
if (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 business map 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}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
const mapImageId = data?.BusinessMaps?.imageId;
|
||||
|
||||
if (deleteImage.ok) {
|
||||
console.log(`Success delete image`);
|
||||
if (mapImageId) {
|
||||
const deleteImage = await fetch(
|
||||
`https://wibu-storage.wibudev.com/api/files/${mapImageId}/delete`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (deleteImage.ok) {
|
||||
console.log(`Success delete business map image `);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const deletePortoMedsos = await prisma.portofolio_MediaSosial.delete({
|
||||
where: {
|
||||
portofolioId: id,
|
||||
},
|
||||
});
|
||||
|
||||
const deleteMap = await prisma.businessMaps.delete({
|
||||
where: {
|
||||
portofolioId: id,
|
||||
},
|
||||
});
|
||||
|
||||
const deletePortofolio = await prisma.portofolio.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
} 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 }
|
||||
@@ -205,9 +221,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
let message;
|
||||
|
||||
if (category === "detail") {
|
||||
console.log("UPDATE PORTOFOLIO DETAIL >>");
|
||||
console.log("DATA >>", data);
|
||||
|
||||
const checkData = await prisma.portofolio.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
@@ -222,8 +235,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
});
|
||||
}
|
||||
|
||||
console.log("CHECK DATA >>", checkData);
|
||||
|
||||
const updateDetail = await prisma.portofolio.update({
|
||||
where: { id },
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user