@@ -113,7 +113,6 @@ model Images {
|
||||
Donasi_Kabar Donasi_Kabar[]
|
||||
Donasi_PencairanDana Donasi_PencairanDana[]
|
||||
Donasi_Invoice Donasi_Invoice[]
|
||||
Portofolio Portofolio[]
|
||||
Image_Map BusinessMaps[] @relation("ImageMap")
|
||||
Image_Pin BusinessMaps[] @relation("ImagePin")
|
||||
Investasi_Invoice Investasi_Invoice[]
|
||||
@@ -143,11 +142,9 @@ model Portofolio {
|
||||
profileId String?
|
||||
MasterBidangBisnis MasterBidangBisnis @relation(fields: [masterBidangBisnisId], references: [id])
|
||||
masterBidangBisnisId String
|
||||
Logo Images? @relation(fields: [logoId], references: [id])
|
||||
logoId String?
|
||||
Portofolio_MediaSosial Portofolio_MediaSosial?
|
||||
BusinessMaps BusinessMaps?
|
||||
imageId String?
|
||||
logoId String?
|
||||
}
|
||||
|
||||
model Portofolio_MediaSosial {
|
||||
|
||||
@@ -18,7 +18,7 @@ const MAPBOX_TOKEN = process.env.MAPBOX_TOKEN!;
|
||||
const WS_APIKEY = process.env.WS_APIKEY!;
|
||||
|
||||
if (!DATABASE_URL) throw new Error("Require DATABASE_URL");
|
||||
if (!WIBU_PWD) throw new Error("Require PWD");
|
||||
if (!WIBU_PWD) throw new Error("Require WIBU_PWD");
|
||||
if (!Client_KEY) throw new Error("Require Client_KEY");
|
||||
if (!Server_KEY) throw new Error("Require Server_KEY");
|
||||
if (!MAPBOX_TOKEN) throw new Error("Require MAPBOX_TOKEN");
|
||||
|
||||
@@ -11,17 +11,19 @@ import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import funCreatePortofolio from "../../fun/fun_create_portofolio";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
|
||||
export function Portofolio_ComponentButtonSelanjutnya({
|
||||
profileId,
|
||||
dataPorto,
|
||||
dataPortofolio,
|
||||
file,
|
||||
dataMedsos,
|
||||
setIsFile,
|
||||
}: {
|
||||
profileId: string;
|
||||
dataPorto: MODEL_PORTOFOLIO_OLD;
|
||||
file: FormData;
|
||||
dataPortofolio: MODEL_PORTOFOLIO_OLD;
|
||||
file: File;
|
||||
dataMedsos: any;
|
||||
setIsFile: any;
|
||||
}) {
|
||||
@@ -30,29 +32,30 @@ export function Portofolio_ComponentButtonSelanjutnya({
|
||||
|
||||
async function onSubmit() {
|
||||
const porto = {
|
||||
namaBisnis: dataPorto.namaBisnis,
|
||||
masterBidangBisnisId: dataPorto.masterBidangBisnisId,
|
||||
alamatKantor: dataPorto.alamatKantor,
|
||||
tlpn: dataPorto.tlpn,
|
||||
deskripsi: dataPorto.deskripsi,
|
||||
namaBisnis: dataPortofolio.namaBisnis,
|
||||
masterBidangBisnisId: dataPortofolio.masterBidangBisnisId,
|
||||
alamatKantor: dataPortofolio.alamatKantor,
|
||||
tlpn: dataPortofolio.tlpn,
|
||||
deskripsi: dataPortofolio.deskripsi,
|
||||
};
|
||||
|
||||
if (_.values(porto).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
if (file === null) {
|
||||
setIsFile(true);
|
||||
return null;
|
||||
}
|
||||
|
||||
const gambar = new FormData();
|
||||
gambar.append("file", file as any);
|
||||
const uploadFile = await funGlobal_UploadToStorage({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.portofolio_logo,
|
||||
});
|
||||
|
||||
const res = await funCreatePortofolio(
|
||||
profileId,
|
||||
porto as any,
|
||||
gambar,
|
||||
dataMedsos
|
||||
);
|
||||
if (!uploadFile.success)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||
|
||||
const res = await funCreatePortofolio({
|
||||
profileId: profileId,
|
||||
data: dataPortofolio as any,
|
||||
medsos: dataMedsos,
|
||||
fileId: uploadFile.data.id,
|
||||
});
|
||||
if (res.status === 201) {
|
||||
setLoading(true);
|
||||
// ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan");
|
||||
@@ -64,7 +67,7 @@ export function Portofolio_ComponentButtonSelanjutnya({
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
disabled={_.values(dataPorto).includes("") || file === null}
|
||||
disabled={_.values(dataPortofolio).includes("") || file === null}
|
||||
mt={"md"}
|
||||
radius={50}
|
||||
loading={loading ? true : false}
|
||||
|
||||
@@ -326,7 +326,7 @@ export default function CreatePortofolio({
|
||||
</Stack>
|
||||
|
||||
<Portofolio_ComponentButtonSelanjutnya
|
||||
dataPorto={dataPortofolio as any}
|
||||
dataPortofolio={dataPortofolio as any}
|
||||
dataMedsos={dataMedsos}
|
||||
file={file}
|
||||
profileId={profileId}
|
||||
|
||||
@@ -8,32 +8,17 @@ import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import fs from "fs";
|
||||
|
||||
export default async function funCreatePortofolio(
|
||||
profileId: string,
|
||||
data: MODEL_PORTOFOLIO,
|
||||
file: FormData,
|
||||
medsos: MODEL_PORTOFOLIO_MEDSOS
|
||||
) {
|
||||
const gambar: any = file.get("file");
|
||||
const fileName = gambar.name;
|
||||
const fileExtension = _.lowerCase(gambar.name.split(".").pop());
|
||||
const fRandomName = v4(fileName) + "." + fileExtension;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
label: "PORTOFOLIO_LOGO",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload) return { status: 400, message: "Gagal upload logo portofolio" };
|
||||
const upload_Folder = Buffer.from(await gambar.arrayBuffer());
|
||||
fs.writeFileSync(`./public/portofolio/logo/${upload.url}`, upload_Folder);
|
||||
|
||||
export default async function funCreatePortofolio({
|
||||
profileId,
|
||||
data,
|
||||
fileId,
|
||||
medsos,
|
||||
}: {
|
||||
profileId: string;
|
||||
data: MODEL_PORTOFOLIO;
|
||||
fileId: string;
|
||||
medsos: MODEL_PORTOFOLIO_MEDSOS;
|
||||
}) {
|
||||
const createPortofolio = await prisma.portofolio.create({
|
||||
data: {
|
||||
profileId: profileId,
|
||||
@@ -43,11 +28,12 @@ export default async function funCreatePortofolio(
|
||||
tlpn: data.tlpn,
|
||||
alamatKantor: data.alamatKantor,
|
||||
masterBidangBisnisId: data.masterBidangBisnisId,
|
||||
logoId: upload.id,
|
||||
logoId: fileId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!createPortofolio) return { status: 400, message: "Gagal membuat portofolio" };
|
||||
if (!createPortofolio)
|
||||
return { status: 400, message: "Gagal membuat portofolio" };
|
||||
|
||||
const createMedsos = await prisma.portofolio_MediaSosial.create({
|
||||
data: {
|
||||
|
||||
@@ -12,7 +12,7 @@ const MAPBOX_TOKEN = process.env.MAPBOX_TOKEN!;
|
||||
const WS_APIKEY = process.env.WS_APIKEY!;
|
||||
|
||||
if (!DATABASE_URL) throw new Error("Require DATABASE_URL");
|
||||
if (!WIBU_PWD) throw new Error("Require PWD");
|
||||
if (!WIBU_PWD) throw new Error("Require WIBU_PWD");
|
||||
if (!Client_KEY) throw new Error("Require Client_KEY");
|
||||
if (!Server_KEY) throw new Error("Require Server_KEY");
|
||||
if (!MAPBOX_TOKEN) throw new Error("Require MAPBOX_TOKEN");
|
||||
Reference in New Issue
Block a user