database investasi

# feat:
- Create investasi
- Edit investasi
- Ubah status investasi
- Masukan berita
### No issue
This commit is contained in:
2023-11-07 21:22:53 +08:00
parent 9fcbba24e3
commit b662b714ad
88 changed files with 1386 additions and 637 deletions

View File

@@ -0,0 +1,99 @@
"use server";
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";
async function up1(data: any) {}
async function up2(data: any, formData: any) {}
export default async function funEditInvestasi(
formData: FormData,
data: MODEL_Investasi
) {
const file = formData.get("file")?.length;
if (file === undefined) {
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;
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);
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",
};
} else {
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",
};
}
}