Prospektus Investasi
# feat: - Halaman upload - Function upload - Get data prospektus ### No issue
This commit is contained in:
32
src/app_modules/investasi/fun/fun_load_data.ts
Normal file
32
src/app_modules/investasi/fun/fun_load_data.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function funLoadDataInvestasi(id: string) {
|
||||
const data = await prisma.investasi.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
hargaLembar: true,
|
||||
targetDana: true,
|
||||
totalLembar: true,
|
||||
roi: true,
|
||||
active: true,
|
||||
imagesId: true,
|
||||
MasterStatusInvestasi: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
SahamTerbeli: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
45
src/app_modules/investasi/fun/fun_upload_prospek.ts
Normal file
45
src/app_modules/investasi/fun/fun_upload_prospek.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
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";
|
||||
|
||||
export default async function funUploadProspektusInvestasi(
|
||||
formData: FormData,
|
||||
idInves: string
|
||||
) {
|
||||
// console.log(formData)
|
||||
|
||||
const file: any = formData.get("file");
|
||||
const fName = file.name;
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
// console.log(fName)
|
||||
// console.log(fExt)
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
|
||||
const uploadFile = await prisma.prospektusInvestasi.upsert({
|
||||
where: {
|
||||
investasiId: idInves,
|
||||
},
|
||||
update: {
|
||||
url: fRandomName,
|
||||
},
|
||||
create: {
|
||||
investasiId: idInves,
|
||||
url: fRandomName,
|
||||
},
|
||||
});
|
||||
|
||||
if(!uploadFile) return {status: 400, message: "Gagal Upload"}
|
||||
const upFolder = Buffer.from(await file.arrayBuffer())
|
||||
fs.writeFileSync(`./public/file/${uploadFile.url}`, upFolder)
|
||||
|
||||
revalidatePath(RouterInvestasi.edit_prospektus)
|
||||
return {
|
||||
status: 201,
|
||||
message: "File tersimpan "
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user