fix: Map
Deskripsi: - Tampilan map - Tampilan portofolio - Kirim file ke wibu storage ## No Image
This commit is contained in:
@@ -3,42 +3,24 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterMap } from "@/app/lib/router_hipmi/router_map";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export async function map_funCreatePin({ data }: { data: any }) {
|
||||
export async function map_funCreatePin({
|
||||
data,
|
||||
}: {
|
||||
data: Prisma.BusinessMapsCreateInput;
|
||||
}) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const gambar: any = data.gambar.get("file");
|
||||
const fileName = gambar.name;
|
||||
const fileExtension = _.lowerCase(gambar.name.split(".").pop());
|
||||
const fRandomName = v4(fileName) + "." + fileExtension;
|
||||
|
||||
const uploadImage = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
label: "MAP_PHOTO",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!uploadImage) return { status: 400, message: "Gagal upload foto lokasi" };
|
||||
const upload_Folder = Buffer.from(await gambar.arrayBuffer());
|
||||
fs.writeFileSync(`./public/map/foto/${uploadImage.url}`, upload_Folder);
|
||||
|
||||
const create = await prisma.businessMaps.create({
|
||||
data: {
|
||||
latitude: data.lat,
|
||||
longitude: data.long,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
namePin: data.namePin,
|
||||
portofolioId: data?.portofolioId,
|
||||
portofolioId: data.Portofolio?.create?.id,
|
||||
authorId: userLoginId,
|
||||
imageMapId: uploadImage.id,
|
||||
imageId: data.imageId,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user