database investasi
# feat: - Create investasi - Edit investasi - Ubah status investasi - Masukan berita ### No issue
This commit is contained in:
62
src/app_modules/investasi/fun/fun_create_berita.ts
Normal file
62
src/app_modules/investasi/fun/fun_create_berita.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
"use server";
|
||||
|
||||
import _ from "lodash";
|
||||
import { MODEL_Investasi } from "../model/model_investasi";
|
||||
import { v4 } from "uuid";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import fs from "fs";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
|
||||
export default async function funCreateBeritaInvestasi(
|
||||
formData: FormData,
|
||||
data: any
|
||||
) {
|
||||
|
||||
const file: any = formData.get("file");
|
||||
const fName = file.name;
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload)
|
||||
return {
|
||||
status: 400,
|
||||
message: "File Kosong",
|
||||
};
|
||||
|
||||
const upFolder = Buffer.from(await file.arrayBuffer());
|
||||
fs.writeFileSync(`./public/investasi/${upload.url}`, upFolder);
|
||||
|
||||
const createBerita = await prisma.beritaInvestasi.create({
|
||||
data: {
|
||||
title: data.title,
|
||||
deskripsi: data.deskripsi,
|
||||
imagesId: upload.id,
|
||||
investasiId: data.investasiId
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!createBerita)
|
||||
return {
|
||||
status: 400,
|
||||
message: "Gagal Disimpan",
|
||||
};
|
||||
|
||||
revalidatePath(RouterInvestasi.list_edit_berita);
|
||||
|
||||
return {
|
||||
status: 201,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
}
|
||||
@@ -4,12 +4,16 @@ import prisma from "@/app/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import fs from "fs";
|
||||
import { INVESTASI } from "@/app_modules/models/investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { MODEL_Investasi } from "../model/model_investasi";
|
||||
|
||||
export async function funCreateInvestasi(formData: FormData, data: INVESTASI) {
|
||||
export async function funCreateInvestasi(
|
||||
formData: FormData,
|
||||
data: MODEL_Investasi | any
|
||||
) {
|
||||
console.log(data)
|
||||
const file: any = formData.get("file");
|
||||
// console.log(file)
|
||||
const fName = file.name;
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
@@ -30,17 +34,6 @@ export async function funCreateInvestasi(formData: FormData, data: INVESTASI) {
|
||||
message: "File Kosong",
|
||||
};
|
||||
|
||||
// if (upload) {
|
||||
// await prisma.investasi.update({
|
||||
// where: {
|
||||
// authorId: data.authorId,
|
||||
// },
|
||||
// data: {
|
||||
// imagesId: upload.id,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
const upFolder = Buffer.from(await file.arrayBuffer());
|
||||
fs.writeFileSync(`./public/investasi/${upload.url}`, upFolder);
|
||||
|
||||
@@ -48,14 +41,15 @@ export async function funCreateInvestasi(formData: FormData, data: INVESTASI) {
|
||||
data: {
|
||||
authorId: data.authorId,
|
||||
title: data.title,
|
||||
targetDana: data.targetDana,
|
||||
hargaLembar: data.hargaLembar,
|
||||
totalLembar: data.totalLembar,
|
||||
roi: data.roi,
|
||||
masterPembagianDevidenId: data.masterPembagianDevidenId,
|
||||
masterPeriodeDevidenId: data.masterPeriodeDevidenId,
|
||||
targetDana: data.targetDana.toString(),
|
||||
hargaLembar: data.hargaLembar.toString(),
|
||||
totalLembar: data.totalLembar.toString(),
|
||||
roi: data.roi.toString(),
|
||||
masterPembagianDevidenId: data.masterPeriodeDevidenId,
|
||||
masterPeriodeDevidenId: data.masterPembagianDevidenId,
|
||||
masterPencarianInvestorId: data.masterPencarianInvestorId,
|
||||
imagesId: upload.id,
|
||||
masterStatusInvestasiId: "1",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -65,7 +59,7 @@ export async function funCreateInvestasi(formData: FormData, data: INVESTASI) {
|
||||
message: "Gagal Disimpan",
|
||||
};
|
||||
|
||||
revalidatePath("/dev/investasi/main");
|
||||
revalidatePath(RouterInvestasi.main_porto);
|
||||
|
||||
return {
|
||||
status: 201,
|
||||
|
||||
21
src/app_modules/investasi/fun/fun_delete_berita.ts
Normal file
21
src/app_modules/investasi/fun/fun_delete_berita.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function funDeleteBeritaInvestasi(id: string, idInvestasi: string) {
|
||||
|
||||
const res = await prisma.beritaInvestasi.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal hapus" };
|
||||
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berita terhapus",
|
||||
};
|
||||
}
|
||||
54
src/app_modules/investasi/fun/fun_edit_berita.ts
Normal file
54
src/app_modules/investasi/fun/fun_edit_berita.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { Model_Berita_Investasi } from "../model/model_investasi";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import fs from "fs";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function funEditBeritaInvestasi(
|
||||
formData: FormData,
|
||||
data: Model_Berita_Investasi
|
||||
) {
|
||||
const fl = formData.get("file");
|
||||
|
||||
if (fl !== "null") {
|
||||
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);
|
||||
revalidatePath("/dev/investasi/list_edit_berita");
|
||||
}
|
||||
|
||||
const res = await prisma.beritaInvestasi.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
title: data.title,
|
||||
deskripsi: data.deskripsi,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal Update" };
|
||||
revalidatePath("/dev/investasi/list_edit_berita");
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil Update",
|
||||
};
|
||||
}
|
||||
99
src/app_modules/investasi/fun/fun_edit_investasi.ts
Normal file
99
src/app_modules/investasi/fun/fun_edit_investasi.ts
Normal 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",
|
||||
};
|
||||
}
|
||||
}
|
||||
23
src/app_modules/investasi/fun/fun_ganti_status.ts
Normal file
23
src/app_modules/investasi/fun/fun_ganti_status.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function funGantiStatusInvestasi(id: string, val: string) {
|
||||
const data = await prisma.investasi.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
masterStatusInvestasiId: val,
|
||||
},
|
||||
});
|
||||
|
||||
if(!data) return {status: 400}
|
||||
|
||||
revalidatePath("/dev/investasi/main/portofolio")
|
||||
|
||||
return {
|
||||
status: 200
|
||||
}
|
||||
}
|
||||
34
src/app_modules/investasi/fun/get_investasi_by_id.ts
Normal file
34
src/app_modules/investasi/fun/get_investasi_by_id.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function getInvestasiById(id: string) {
|
||||
const data = await prisma.user.findUnique({
|
||||
where: { id: id },
|
||||
select: {
|
||||
Investasi: {
|
||||
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?.Investasi;
|
||||
}
|
||||
12
src/app_modules/investasi/fun/get_one_berita_by_id.ts
Normal file
12
src/app_modules/investasi/fun/get_one_berita_by_id.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
"use server"
|
||||
|
||||
import prisma from "@/app/lib/prisma"
|
||||
|
||||
export default async function getOneBeritaInvestasiById(id: string) {
|
||||
const res = await prisma.beritaInvestasi.findUnique({
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
})
|
||||
return res;
|
||||
}
|
||||
32
src/app_modules/investasi/fun/get_one_investasi_by_id.ts
Normal file
32
src/app_modules/investasi/fun/get_one_investasi_by_id.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { data } from "autoprefixer";
|
||||
|
||||
export default async function getOneInvestasiById(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;
|
||||
}
|
||||
14
src/app_modules/investasi/fun/master/get_status_investasi.ts
Normal file
14
src/app_modules/investasi/fun/master/get_status_investasi.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function getStatusInvestasi() {
|
||||
const data = await prisma.masterStatusInvestasi.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
color: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user