title: auto

des: auto
note:auto
This commit is contained in:
2023-11-09 17:13:13 +08:00
parent 39d9085ccb
commit 9b954b902d
4 changed files with 49 additions and 53 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

@@ -35,13 +35,11 @@ import { useDisclosure, useWindowScroll } from "@mantine/hooks";
import { test_server } from "./_makuro/test_server";
export default function EditIntroInvestasi({
dataInvestasi,
listPencarian,
listPeriode,
listPembagian,
}: {
dataInvestasi: MODEL_Investasi;
listPencarian: MODEL_DEFAULT_MASTER[];
listPeriode: MODEL_DEFAULT_MASTER[];
@@ -70,13 +68,11 @@ export default function EditIntroInvestasi({
const fd = new FormData();
fd.append("file", fl as any);
// await funEditInvestasi(fd, body).then(async (res) => {
// res.status === 200
// ? (toast(res.message), router.back())
// : toast(res.message);
// });
await funEditInvestasi(fd, body).then(async (res) => {
res.status === 200
? (toast(res.message), router.back())
: toast(res.message);
});
}
return (

View File

@@ -3,10 +3,10 @@
import prisma from "@/app/lib/prisma";
import { MODEL_Investasi } from "../model/model_investasi";
import _ from "lodash";
// import { v4 } from "uuid";
// import fs from "fs";
// import { revalidatePath } from "next/cache";
// import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
import { v4 } from "uuid";
import fs from "fs";
import { revalidatePath } from "next/cache";
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
export default async function funEditInvestasi(
formData: FormData,
@@ -15,50 +15,50 @@ export default async function funEditInvestasi(
const file = formData.get("file");
if (file !== "null") {
// const editInves = await prisma.investasi.update({
// where: {
// id: data.id,
// },
// data: {
// title: data.title,
// targetDana: data.targetDana,
// hargaLembar: data.hargaLembar,
// totalLembar: data.totalLembar,
// roi: data.roi,
// masterPencarianInvestorId: data.MasterPencarianInvestor.id,
// masterPembagianDevidenId: data.MasterPembagianDeviden.id,
// masterPeriodeDevidenId: data.MasterPeriodeDeviden.id,
// },
// });
const file: any = formData.get("file");
const fName = file.name;
const fExt =
file && file.name ? _.lowerCase(file.name.split(".").pop()) : "";
const fRandomName = v4(fName) + "." + fExt;
// if (!editInves) {
// return {
// status: 400,
// message: "Gagal update",
// };
// }
const updateImage = await prisma.images.update({
where: {
id: data.imagesId,
},
data: {
url: fRandomName,
},
});
// const file: any = formData.get("file");
// const fName = file.name;
// const fExt =
// file && file.name ? _.lowerCase(file.name.split(".").pop()) : "";
// const fRandomName = "file_" + _.random(100000000, 999999999999) + "." + fExt;
// const updateImage = await prisma.images.update({
// where: {
// id: data.imagesId,
// },
// data: {
// url: fRandomName,
// },
// });
// if (!updateImage) return { status: 400, message: "Gagal upload gambar" };
// const upFolder = Buffer.from(await file.arrayBuffer());
// fs.writeFileSync(`./public/investasi/${updateImage.url}`, upFolder);
if (!updateImage) return { status: 400, message: "Gagal upload gambar" };
const upFolder = Buffer.from(await file.arrayBuffer());
fs.writeFileSync(`./public/investasi/${updateImage.url}`, upFolder);
}
// revalidatePath(RouterInvestasi.detail_draft);
const editInves = await prisma.investasi.update({
where: {
id: data.id,
},
data: {
title: data.title,
targetDana: data.targetDana,
hargaLembar: data.hargaLembar,
totalLembar: data.totalLembar,
roi: data.roi,
masterPencarianInvestorId: data.MasterPencarianInvestor.id,
masterPembagianDevidenId: data.MasterPembagianDeviden.id,
masterPeriodeDevidenId: data.MasterPeriodeDeviden.id,
},
});
if (!editInves) {
return {
status: 400,
message: "Gagal update",
};
}
revalidatePath(RouterInvestasi.detail_draft);
return {
status: 200,
message: "Berhasil Disimpan",