Revisi tampilan
fix: - alur pembuatan investasi - tampilan investasi ### No issue
This commit is contained in:
@@ -9,21 +9,17 @@ import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { MODEL_Investasi } from "../model/model_investasi";
|
||||
|
||||
export async function funCreateInvestasi(
|
||||
formData: FormData,
|
||||
gamabar: FormData,
|
||||
filePdf: FormData,
|
||||
data: MODEL_Investasi | any
|
||||
) {
|
||||
|
||||
// return {
|
||||
// status: 201,
|
||||
// message: "Berhasil Disimpan",
|
||||
// };
|
||||
|
||||
const file: any = formData.get("file");
|
||||
// Function upload gambar
|
||||
const file: any = gamabar.get("file");
|
||||
const fName = file.name;
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
const uploadImage = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
},
|
||||
@@ -33,16 +29,14 @@ export async function funCreateInvestasi(
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload)
|
||||
if (!uploadImage)
|
||||
return {
|
||||
status: 400,
|
||||
message: "File Kosong",
|
||||
};
|
||||
|
||||
const upFolder = Buffer.from(await file.arrayBuffer());
|
||||
fs.writeFileSync(`./public/investasi/${upload.url}`, upFolder);
|
||||
|
||||
// console.log(data)
|
||||
fs.writeFileSync(`./public/investasi/${uploadImage.url}`, upFolder);
|
||||
|
||||
const createInvest = await prisma.investasi.create({
|
||||
data: {
|
||||
@@ -51,23 +45,46 @@ export async function funCreateInvestasi(
|
||||
targetDana: data.targetDana.toString(),
|
||||
hargaLembar: data.hargaLembar.toString(),
|
||||
totalLembar: data.totalLembar.toString(),
|
||||
sisaLembar: data.totalLembar.toString() ,
|
||||
sisaLembar: data.totalLembar.toString(),
|
||||
roi: data.roi.toString(),
|
||||
masterPembagianDevidenId: data.masterPeriodeDevidenId,
|
||||
masterPeriodeDevidenId: data.masterPembagianDevidenId,
|
||||
masterPencarianInvestorId: data.masterPencarianInvestorId,
|
||||
imagesId: upload.id,
|
||||
masterStatusInvestasiId: "1",
|
||||
imagesId: uploadImage.id,
|
||||
masterStatusInvestasiId: "2",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!createInvest)
|
||||
return {
|
||||
status: 400,
|
||||
message: "Gagal Disimpan",
|
||||
};
|
||||
|
||||
// File upload function
|
||||
const dataPdf: any = filePdf.get("file");
|
||||
const pdfName = dataPdf.name;
|
||||
const pdfExt = _.lowerCase(dataPdf.name.split(".").pop());
|
||||
const pdfRandomName = v4(pdfName) + "." + pdfExt;
|
||||
|
||||
const uploadFile = await prisma.prospektusInvestasi.upsert({
|
||||
where: {
|
||||
investasiId: createInvest.id,
|
||||
},
|
||||
update: {
|
||||
url: pdfRandomName,
|
||||
},
|
||||
create: {
|
||||
investasiId: createInvest.id,
|
||||
url: pdfRandomName,
|
||||
},
|
||||
});
|
||||
|
||||
if(!uploadFile) return {status: 400, message: "Gagal Upload"}
|
||||
const upPdfFolder = Buffer.from(await file.arrayBuffer())
|
||||
fs.writeFileSync(`./public/file/${uploadFile.url}`, upPdfFolder)
|
||||
|
||||
|
||||
revalidatePath(RouterInvestasi.main_porto);
|
||||
|
||||
return {
|
||||
|
||||
@@ -41,9 +41,9 @@ export default async function funEditInvestasi(
|
||||
},
|
||||
data: {
|
||||
title: data.title,
|
||||
targetDana: data.targetDana,
|
||||
hargaLembar: data.hargaLembar,
|
||||
totalLembar: data.totalLembar,
|
||||
targetDana: "" + data.targetDana,
|
||||
hargaLembar: "" + data.hargaLembar,
|
||||
totalLembar: "" + data.totalLembar,
|
||||
roi: data.roi,
|
||||
masterPencarianInvestorId: data.MasterPencarianInvestor.id,
|
||||
masterPembagianDevidenId: data.MasterPembagianDeviden.id,
|
||||
|
||||
@@ -20,7 +20,7 @@ export default async function getPortoByStatusId(id: string, statusId: number) {
|
||||
title: true,
|
||||
imagesId: true,
|
||||
// hargaLembar: true,
|
||||
// targetDana: true,
|
||||
targetDana: true,
|
||||
// totalLembar: true,
|
||||
// roi: true,
|
||||
// active: true,
|
||||
@@ -53,6 +53,7 @@ export default async function getPortoByStatusId(id: string, statusId: number) {
|
||||
id: true,
|
||||
title: true,
|
||||
imagesId: true,
|
||||
targetDana: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
@@ -75,6 +76,7 @@ export default async function getPortoByStatusId(id: string, statusId: number) {
|
||||
title: true,
|
||||
imagesId: true,
|
||||
updatedAt: true,
|
||||
targetDana: true,
|
||||
MasterPencarianInvestor: true,
|
||||
},
|
||||
});
|
||||
@@ -97,6 +99,7 @@ export default async function getPortoByStatusId(id: string, statusId: number) {
|
||||
id: true,
|
||||
title: true,
|
||||
imagesId: true,
|
||||
targetDana: true
|
||||
},
|
||||
});
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user