# feat :
## Deskripsi : - Notifikasi investasi ## Issue : Gerbang pembayaran
This commit is contained in:
40
src/app_modules/investasi/fun/edit/fun_edit_status_by_id.ts
Normal file
40
src/app_modules/investasi/fun/edit/fun_edit_status_by_id.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function investasi_funEditStatusById({
|
||||
investasiId,
|
||||
statusId,
|
||||
}: {
|
||||
investasiId: string;
|
||||
statusId: string;
|
||||
}) {
|
||||
const res = await prisma.investasi.update({
|
||||
where: {
|
||||
id: investasiId,
|
||||
},
|
||||
data: {
|
||||
masterStatusInvestasiId: statusId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
MasterStatusInvestasi: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal Update" };
|
||||
revalidatePath(RouterInvestasi.main_porto);
|
||||
return {
|
||||
data: res,
|
||||
status: 200,
|
||||
message: "Update Berhasil",
|
||||
};
|
||||
}
|
||||
@@ -10,19 +10,20 @@ import { MODEL_Investasi } from "../model/model_investasi";
|
||||
import funUploadProspektusInvestasi from "./fun_upload_prospek";
|
||||
|
||||
export async function funCreateInvestasi(
|
||||
gamabar: FormData,
|
||||
fileGambar: FormData,
|
||||
filePdf: FormData,
|
||||
data: MODEL_Investasi
|
||||
) {
|
||||
// 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 gambar: any = fileGambar.get("file");
|
||||
const gambarName = gambar.name;
|
||||
const gambarExtention = _.lowerCase(gambar.name.split(".").pop());
|
||||
const gambarRandomName = v4(gambarName) + "." + gambarExtention;
|
||||
|
||||
const uploadImage = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
url: gambarRandomName,
|
||||
label: "INVESTASI",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -36,13 +37,13 @@ export async function funCreateInvestasi(
|
||||
message: "Gambar Kosong",
|
||||
};
|
||||
|
||||
const upFolder = Buffer.from(await file.arrayBuffer());
|
||||
const upFolder = Buffer.from(await gambar.arrayBuffer());
|
||||
fs.writeFileSync(`./public/investasi/${uploadImage.url}`, upFolder);
|
||||
|
||||
const createInvest = await prisma.investasi.create({
|
||||
data: {
|
||||
authorId: data.authorId,
|
||||
title: data.title,
|
||||
title: _.startCase(data.title),
|
||||
targetDana: data.targetDana.toString(),
|
||||
hargaLembar: data.hargaLembar.toString(),
|
||||
totalLembar: data.totalLembar.toString(),
|
||||
@@ -54,6 +55,16 @@ export async function funCreateInvestasi(
|
||||
imagesId: uploadImage.id,
|
||||
masterStatusInvestasiId: "2",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
MasterStatusInvestasi: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!createInvest)
|
||||
@@ -62,32 +73,27 @@ export async function funCreateInvestasi(
|
||||
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;
|
||||
// await funUploadProspektusInvestasi(filePdf, createInvest.id);
|
||||
|
||||
// const uploadFile = await prisma.prospektusInvestasi.create({
|
||||
// data: {
|
||||
// investasiId: createInvest.id,
|
||||
// url: pdfRandomName,
|
||||
// },
|
||||
// select: {
|
||||
// id: true,
|
||||
// url: true,
|
||||
// },
|
||||
// });
|
||||
const file: any = filePdf.get("file");
|
||||
const fName = file.name;
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
|
||||
// if (!uploadFile) return { status: 400, message: "File Kosong" };
|
||||
// const upPdfFolder = Buffer.from(await file.arrayBuffer());
|
||||
// fs.writeFileSync(`./public/file/${uploadFile.url}`, upPdfFolder);
|
||||
const createFile = await prisma.prospektusInvestasi.create({
|
||||
data: {
|
||||
investasiId: createInvest.id,
|
||||
url: fRandomName,
|
||||
},
|
||||
});
|
||||
|
||||
await funUploadProspektusInvestasi(filePdf, createInvest.id);
|
||||
if (!createFile) return { status: 400, message: "Gagal Upload" };
|
||||
const uploadFile = Buffer.from(await file.arrayBuffer());
|
||||
fs.writeFileSync(`./public/file/${createFile.url}`, uploadFile);
|
||||
|
||||
revalidatePath(RouterInvestasi.main_porto);
|
||||
|
||||
return {
|
||||
data: createInvest,
|
||||
status: 201,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
|
||||
@@ -14,10 +14,7 @@ export default async function funDeleteInvestasi(id: string) {
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal Hapus Data" };
|
||||
|
||||
|
||||
revalidatePath(RouterInvestasi.portofolio)
|
||||
revalidatePath(RouterAdminInvestasi_OLD.main_investasi)
|
||||
|
||||
revalidatePath(RouterInvestasi.portofolio);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { v4 } from "uuid";
|
||||
import fs from "fs"
|
||||
import fs from "fs";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
|
||||
@@ -11,12 +11,9 @@ export default async function funUploadProspektusInvestasi(
|
||||
formData: FormData,
|
||||
idInves: string
|
||||
) {
|
||||
|
||||
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({
|
||||
@@ -32,13 +29,13 @@ export default async function funUploadProspektusInvestasi(
|
||||
},
|
||||
});
|
||||
|
||||
if(!uploadFile) return {status: 400, message: "Gagal Upload"}
|
||||
const upFolder = Buffer.from(await file.arrayBuffer())
|
||||
fs.writeFileSync(`./public/file/${uploadFile.url}`, upFolder)
|
||||
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)
|
||||
revalidatePath(RouterInvestasi.edit_prospektus);
|
||||
return {
|
||||
status: 201,
|
||||
message: "File tersimpan "
|
||||
}
|
||||
message: "File tersimpan ",
|
||||
};
|
||||
}
|
||||
|
||||
86
src/app_modules/investasi/fun/get_all_investasi.ts
Normal file
86
src/app_modules/investasi/fun/get_all_investasi.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import moment from "moment";
|
||||
|
||||
export async function investasi_funGetAllPublish() {
|
||||
const data = await prisma.investasi.findMany({
|
||||
where: {
|
||||
masterStatusInvestasiId: "1",
|
||||
masterProgresInvestasiId: "1",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
MasterPencarianInvestor: true,
|
||||
countDown: true,
|
||||
progress: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (let a of data) {
|
||||
if (
|
||||
(a.MasterPencarianInvestor?.name as any) -
|
||||
moment(new Date()).diff(new Date(a.countDown as any), "days") <=
|
||||
0
|
||||
) {
|
||||
// console.log(a.MasterPencarianInvestor?.name);
|
||||
|
||||
await prisma.investasi.update({
|
||||
where: {
|
||||
id: a.id,
|
||||
},
|
||||
data: {
|
||||
masterProgresInvestasiId: "3",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (a.progress === "100") {
|
||||
await prisma.investasi.update({
|
||||
where: {
|
||||
id: a.id,
|
||||
},
|
||||
data: {
|
||||
masterProgresInvestasiId: "2",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// cek data yang lewat
|
||||
// klo ada, update status
|
||||
|
||||
const dataFix = await prisma.investasi.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
masterProgresInvestasiId: "asc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
masterStatusInvestasiId: "1",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
hargaLembar: true,
|
||||
targetDana: true,
|
||||
totalLembar: true,
|
||||
sisaLembar: true,
|
||||
progress: true,
|
||||
roi: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
imagesId: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
MasterProgresInvestasi: true,
|
||||
countDown: true,
|
||||
},
|
||||
});
|
||||
|
||||
return dataFix;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function getAllDataPublishInvestasi() {
|
||||
const data = await prisma.investasi.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
masterProgresInvestasiId: "asc",
|
||||
},
|
||||
{
|
||||
countDown: "desc",
|
||||
},
|
||||
],
|
||||
where: {
|
||||
MasterStatusInvestasi: {
|
||||
name: {
|
||||
equals: "Publish",
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
hargaLembar: true,
|
||||
targetDana: true,
|
||||
totalLembar: true,
|
||||
sisaLembar: true,
|
||||
progress: true,
|
||||
roi: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
imagesId: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
MasterProgresInvestasi: true,
|
||||
countDown: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -17,12 +17,21 @@ export default async function getListTransaksiBerhasilInvestasi(
|
||||
id: true,
|
||||
Investasi: {
|
||||
select: {
|
||||
author: true,
|
||||
author: {
|
||||
select: {
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
userId: true,
|
||||
imagesId: true
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
imagesId: true,
|
||||
title: true,
|
||||
totalLembar: true,
|
||||
sisaLembar: true,
|
||||
|
||||
},
|
||||
},
|
||||
Author: true,
|
||||
|
||||
@@ -6,11 +6,17 @@ export default async function getOneInvestasiById(id: string) {
|
||||
const data = await prisma.investasi.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
|
||||
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
nomor: true,
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
title: true,
|
||||
authorId: true,
|
||||
hargaLembar: true,
|
||||
@@ -33,8 +39,8 @@ export default async function getOneInvestasiById(id: string) {
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
MasterProgresInvestasi: true,
|
||||
author: true,
|
||||
countDown: true
|
||||
masterStatusInvestasiId: true,
|
||||
countDown: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -16,7 +16,13 @@ export default async function getOneTransaksiBerhasilByIdInvestasi(
|
||||
select: {
|
||||
nomor: true,
|
||||
username: true,
|
||||
}
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
imagesId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
|
||||
Reference in New Issue
Block a user