Fix: Investasi
Deskripsi: - Upload gambar investasi ke storage wibu - Upload bukti transfer ke storage wibu # No Issue
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
type ICreateDocument = {
|
||||
investasiId: string;
|
||||
title: string;
|
||||
fileId: string;
|
||||
};
|
||||
export async function investasi_funCreateDocument({
|
||||
data,
|
||||
}: {
|
||||
data: ICreateDocument;
|
||||
}) {
|
||||
const create = await prisma.dokumenInvestasi.create({
|
||||
data: {
|
||||
investasiId: data.investasiId,
|
||||
title: data.title,
|
||||
fileId: data.fileId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal membuat dokumen" };
|
||||
revalidatePath(NEW_RouterInvestasi.rekap_dokumen({ id: data.investasiId }));
|
||||
return { status: 201, message: "Berhasil membuat dokumen" };
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import _ from "lodash";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { MODEL_INVESTASI } from "../../_lib/interface";
|
||||
|
||||
export async function investasi_funCreateNewInvestasi({
|
||||
data,
|
||||
fileImageId,
|
||||
filePdfId,
|
||||
}: {
|
||||
data: MODEL_INVESTASI;
|
||||
fileImageId: string;
|
||||
filePdfId: string;
|
||||
}) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
try {
|
||||
const createNew = await prisma.investasi.create({
|
||||
data: {
|
||||
authorId: userLoginId,
|
||||
title: _.startCase(data.title),
|
||||
targetDana: data.targetDana.toString(),
|
||||
hargaLembar: data.hargaLembar.toString(),
|
||||
totalLembar: data.totalLembar.toString(),
|
||||
sisaLembar: data.totalLembar.toString(),
|
||||
roi: data.roi.toString(),
|
||||
masterPembagianDevidenId: data.masterPembagianDevidenId,
|
||||
masterPeriodeDevidenId: data.masterPeriodeDevidenId,
|
||||
masterPencarianInvestorId: data.masterPencarianInvestorId,
|
||||
masterStatusInvestasiId: "2",
|
||||
imageId: fileImageId,
|
||||
prospektusFileId: filePdfId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
authorId: true,
|
||||
MasterStatusInvestasi: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!createNew) return { status: 400, message: "Gagal Membuat Investasi" };
|
||||
revalidatePath(NEW_RouterInvestasi.portofolio({id: "2"}));
|
||||
|
||||
return {
|
||||
status: 201,
|
||||
data: createNew,
|
||||
message: "Berhasil Membuat Investasi",
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
return { status: 400, message: "Error Message" };
|
||||
}
|
||||
}
|
||||
21
src/app_modules/investasi/_fun/delete/fun_delete_dokumen.tsx
Normal file
21
src/app_modules/investasi/_fun/delete/fun_delete_dokumen.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function investasi_funDeleteDokumenById({
|
||||
dokumenId,
|
||||
}: {
|
||||
dokumenId: string;
|
||||
}) {
|
||||
const del = await prisma.dokumenInvestasi.delete({
|
||||
where: {
|
||||
id: dokumenId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!del) return { status: 400, message: "Gagal hapus data" };
|
||||
revalidatePath(NEW_RouterInvestasi.rekap_dokumen({ id: del.investasiId as any }));
|
||||
return { status: 200, message: "Berhasil hapus data" };
|
||||
}
|
||||
67
src/app_modules/investasi/_fun/edit/fun_edit_document.tsx
Normal file
67
src/app_modules/investasi/_fun/edit/fun_edit_document.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { MODEL_INVESTASI_DOKUMEN } from "../../_lib/interface";
|
||||
import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function investasi_funUpdateDocument({
|
||||
data,
|
||||
fileId,
|
||||
}: {
|
||||
data: MODEL_INVESTASI_DOKUMEN;
|
||||
fileId?: string;
|
||||
}) {
|
||||
try {
|
||||
fileId !== undefined
|
||||
? await prisma.dokumenInvestasi.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
title: data.title,
|
||||
fileId: fileId,
|
||||
},
|
||||
})
|
||||
: await prisma.dokumenInvestasi.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
title: data.title,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
revalidatePath(NEW_RouterInvestasi.rekap_dokumen({ id: data.investasiId }));
|
||||
return { status: 200, message: "Berhasil Update" };
|
||||
}
|
||||
|
||||
// if (fileId !== undefined) {
|
||||
// const updt = await prisma.dokumenInvestasi.update({
|
||||
// where: {
|
||||
// id: data.id,
|
||||
// },
|
||||
// data: {
|
||||
// title: data.title,
|
||||
// fileId: fileId,
|
||||
// },
|
||||
// });
|
||||
// } else {
|
||||
// const updt = await prisma.dokumenInvestasi.update({
|
||||
// where: {
|
||||
// id: data.id,
|
||||
// },
|
||||
// data: {
|
||||
// title: data.title,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// if (!updt) return { status: 400, message: "Gagal Update" };
|
||||
// revalidatePath(NEW_RouterInvestasi.rekap_dokumen({ id: data.investasiId }));
|
||||
// return {
|
||||
// status: 200,
|
||||
// message: "Berhasil Update",
|
||||
// };
|
||||
}
|
||||
67
src/app_modules/investasi/_fun/edit/fun_edit_investasi.tsx
Normal file
67
src/app_modules/investasi/_fun/edit/fun_edit_investasi.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { MODEL_INVESTASI } from "../../_lib/interface";
|
||||
import _ from "lodash";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
|
||||
export async function investasi_funUpdateInvestasi({
|
||||
data,
|
||||
imageId,
|
||||
totalLembar,
|
||||
}: {
|
||||
data: MODEL_INVESTASI;
|
||||
imageId?: string;
|
||||
totalLembar: string;
|
||||
}) {
|
||||
// console.log(data);
|
||||
// console.log(imageId);
|
||||
// console.log(totalLembar);
|
||||
|
||||
if (imageId !== undefined) {
|
||||
const updtWithImage = await prisma.investasi.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
title: _.startCase(data.title),
|
||||
targetDana: data.targetDana,
|
||||
hargaLembar: data.hargaLembar,
|
||||
totalLembar: totalLembar,
|
||||
sisaLembar: totalLembar,
|
||||
roi: data.roi,
|
||||
masterPembagianDevidenId: data.masterPembagianDevidenId,
|
||||
masterPeriodeDevidenId: data.masterPeriodeDevidenId,
|
||||
masterPencarianInvestorId: data.masterPencarianInvestorId,
|
||||
imageId: imageId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updtWithImage) return { status: 400, message: "Gagal update data" };
|
||||
revalidatePath(NEW_RouterInvestasi.detail_draft);
|
||||
return { status: 200, message: "Berhasil update" };
|
||||
} else {
|
||||
const updtNoImage = await prisma.investasi.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
title: _.startCase(data.title),
|
||||
targetDana: data.targetDana,
|
||||
hargaLembar: data.hargaLembar,
|
||||
totalLembar: totalLembar,
|
||||
sisaLembar: totalLembar,
|
||||
roi: data.roi,
|
||||
masterPembagianDevidenId: data.masterPembagianDevidenId,
|
||||
masterPeriodeDevidenId: data.masterPeriodeDevidenId,
|
||||
masterPencarianInvestorId: data.masterPencarianInvestorId,
|
||||
imageId: imageId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updtNoImage) return { status: 400, message: "Gagal update data" };
|
||||
revalidatePath(NEW_RouterInvestasi.detail_draft);
|
||||
return { status: 200, message: "Berhasil update" };
|
||||
}
|
||||
}
|
||||
29
src/app_modules/investasi/_fun/edit/fun_edit_prospektus.tsx
Normal file
29
src/app_modules/investasi/_fun/edit/fun_edit_prospektus.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NEW_RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function investasi_funUpdateProspektus({
|
||||
investasiId,
|
||||
fileId,
|
||||
}: {
|
||||
investasiId: string;
|
||||
fileId: string;
|
||||
}) {
|
||||
const updte = await prisma.investasi.update({
|
||||
where: {
|
||||
id: investasiId,
|
||||
},
|
||||
data: {
|
||||
prospektusFileId: fileId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updte) return { status: 400, message: "Gagal update prospektus" };
|
||||
revalidatePath(NEW_RouterInvestasi.detail_draft);
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil update prospektus",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
|
||||
export async function investasi_funGetAllDocumentById({
|
||||
investasiId,
|
||||
page,
|
||||
}: {
|
||||
investasiId: string;
|
||||
page: number
|
||||
}) {
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.dokumenInvestasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
investasiId: investasiId,
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
"use server"
|
||||
|
||||
import { prisma } from "@/app/lib"
|
||||
|
||||
export async function investasi_funGetOneDocumentById({ documentId }: { documentId: string }) {
|
||||
const data = await prisma.dokumenInvestasi.findFirst({
|
||||
where: {
|
||||
id: documentId
|
||||
}
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -24,6 +24,7 @@ export async function investasi_funGetOneInvestasiById({
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
MasterProgresInvestasi: true,
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
|
||||
export async function investasi_funGetPortofolioByStatusId({
|
||||
page,
|
||||
statusId,
|
||||
}: {
|
||||
page: number;
|
||||
statusId: string;
|
||||
}) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.investasi.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
authorId: userLoginId,
|
||||
masterStatusInvestasiId: statusId,
|
||||
},
|
||||
include: {
|
||||
MasterPencarianInvestor: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -5,6 +5,19 @@ import { investasi_funUploadBuktiTransferById } from "./upload/fun_upload_bukti_
|
||||
import { investasi_funGetSuccessTransactionById } from "./get/fun_get_success_transaction_by_id";
|
||||
import { investasi_funGetAllPublishByUserId } from "./get/fun_get_all_investasi_by_user_id";
|
||||
import { investasi_funGetAllInvestasiNonPublishByUserId } from "./get/fun_get_all_investasi_non_publish_by_user_id";
|
||||
import { investasi_funCreateNewInvestasi } from "./create/fun_create_new_investasi";
|
||||
import { investasi_funGetPortofolioByStatusId } from "./get/fun_get_portofolio_by_status_id";
|
||||
import { investasi_funUpdateInvestasi } from "./edit/fun_edit_investasi";
|
||||
import { investasi_funUpdateProspektus } from "./edit/fun_edit_prospektus";
|
||||
import { investasi_funGetAllDocumentById } from "./get/fun_get_all_document_by_id";
|
||||
import { investasi_funCreateDocument } from "./create/fun_create_document";
|
||||
import { investasi_funGetOneDocumentById } from "./get/fun_get_one_document_by_id";
|
||||
import { investasi_funUpdateDocument } from "./edit/fun_edit_document";
|
||||
import { investasi_funDeleteDokumenById } from "./delete/fun_delete_dokumen";
|
||||
|
||||
// Create
|
||||
export { investasi_funCreateNewInvestasi };
|
||||
export { investasi_funCreateDocument };
|
||||
|
||||
// Get
|
||||
export { investasi_funGetOneInvestasiById };
|
||||
@@ -13,6 +26,17 @@ export { investasi_funGetTransaksiByUserId };
|
||||
export { investasi_funGetSuccessTransactionById };
|
||||
export { investasi_funGetAllPublishByUserId };
|
||||
export { investasi_funGetAllInvestasiNonPublishByUserId };
|
||||
export { investasi_funGetPortofolioByStatusId };
|
||||
export { investasi_funGetAllDocumentById };
|
||||
export { investasi_funGetOneDocumentById };
|
||||
|
||||
// Update
|
||||
export { investasi_funUpdateInvestasi };
|
||||
export { investasi_funUpdateProspektus };
|
||||
export { investasi_funUpdateDocument };
|
||||
|
||||
// Upload
|
||||
export { investasi_funUploadBuktiTransferById };
|
||||
|
||||
// Delete
|
||||
export { investasi_funDeleteDokumenById };
|
||||
|
||||
@@ -7,38 +7,17 @@ import fs from "fs";
|
||||
|
||||
export async function investasi_funUploadBuktiTransferById({
|
||||
invoiceId,
|
||||
file,
|
||||
fileId,
|
||||
}: {
|
||||
invoiceId: string;
|
||||
file: FormData;
|
||||
fileId: string;
|
||||
}) {
|
||||
// console.log(file);
|
||||
const gambar: any = file.get("file");
|
||||
const fileName = gambar.name;
|
||||
const fileExtension = _.lowerCase(gambar.name.split(".").pop());
|
||||
const fileRandomName = v4(fileName) + "." + fileExtension;
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fileRandomName,
|
||||
label: "INVESTASI_INVOICE",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload) return { status: 400, message: "Gagal upload gambar" };
|
||||
const uploadFolder = Buffer.from(await gambar.arrayBuffer());
|
||||
fs.writeFileSync(`./public/investasi/invoice/${upload.url}`, uploadFolder);
|
||||
|
||||
const updateFile = await prisma.investasi_Invoice.update({
|
||||
where: {
|
||||
id: invoiceId,
|
||||
},
|
||||
data: {
|
||||
imagesId: upload.id,
|
||||
imageId: fileId,
|
||||
statusInvoiceId: "2",
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user