diff --git a/CHANGELOG.md b/CHANGELOG.md index 1da15473..44e58aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [1.4.43](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.42...v1.4.43) (2025-09-29) + ## [1.4.42](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.41...v1.4.42) (2025-09-24) ## [1.4.41](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.40...v1.4.41) (2025-09-23) diff --git a/package.json b/package.json index 51672211..eea3308f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.4.42", + "version": "1.4.43", "private": true, "prisma": { "seed": "bun prisma/seed.ts" diff --git a/src/app/api/mobile/investment/[id]/[status]/route.ts b/src/app/api/mobile/investment/[id]/[status]/route.ts new file mode 100644 index 00000000..81b1d3db --- /dev/null +++ b/src/app/api/mobile/investment/[id]/[status]/route.ts @@ -0,0 +1,110 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, PUT }; + +async function GET( + request: Request, + { params }: { params: { id: string; status: string } } +) { + const { id, status } = params; + const fixStatusName = _.startCase(status); + + try { + const data = await prisma.investasi.findMany({ + orderBy: { + updatedAt: "desc", + }, + where: { + authorId: id, + MasterStatusInvestasi: { + name: fixStatusName, + }, + }, + select: { + id: true, + title: true, + targetDana: true, + imageId: true, + countDown: true, + updatedAt: true, + MasterPencarianInvestor: { + select: { + name: true, + }, + }, + }, + }); + + const fixData = data.map((v: any) => ({ + ..._.omit(v, ["MasterPencarianInvestor"]), + pencarianInvestor: v.MasterPencarianInvestor.name, + })); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil Mendapatkan Data", + data: fixData, + }); + } catch (error) { + console.log("[ERROR GET INVESTASI]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error Mendapatkan Data", + reason: error || (error as Error).message, + }); + } +} + +async function PUT( + request: Request, + { params }: { params: { id: string; status: string } } +) { + const { id, status } = params; + const fixStatusName = _.startCase(status); + + console.log("[PUT INVESTASI]", id, fixStatusName); + + try { + const checkStatus = await prisma.masterStatusInvestasi.findFirst({ + where: { + name: fixStatusName, + }, + }); + + if (!checkStatus) { + return NextResponse.json({ + success: false, + message: "Status tidak ditemukan", + status: 404, + }); + } + + const updateData = await prisma.investasi.update({ + where: { + id: id, + }, + data: { + masterStatusInvestasiId: checkStatus.id, + }, + }); + + console.log("[UPDATE INVESTASI]", updateData); + + return NextResponse.json({ + status: 200, + success: true, + message: "Update berhasil", + }); + } catch (error) { + return NextResponse.json({ + status: 500, + success: false, + message: "Error Update Data", + reason: error || (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/investment/[id]/route.ts b/src/app/api/mobile/investment/[id]/route.ts new file mode 100644 index 00000000..abf553a6 --- /dev/null +++ b/src/app/api/mobile/investment/[id]/route.ts @@ -0,0 +1,138 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, DELETE, PUT }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + const data = await prisma.investasi.findUnique({ + where: { + id: id, + }, + include: { + author: { + include: { + Profile: true, + }, + }, + Investasi_Invoice: true, + MasterStatusInvestasi: true, + BeritaInvestasi: true, + DokumenInvestasi: true, + ProspektusInvestasi: true, + MasterPembagianDeviden: true, + MasterPencarianInvestor: true, + MasterPeriodeDeviden: true, + MasterProgresInvestasi: true, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil Mendapatkan Data", + data: data, + }); + } catch (error) { + return NextResponse.json({ + status: 500, + success: false, + message: "Error Mendapatkan Data", + reason: (error as Error).message, + }); + } +} + +async function DELETE( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + + try { + // const checkData = await prisma.investasi.findUnique({ + // where: { + // id: id, + // }, + // }); + + // if (!checkData) { + // return NextResponse.json({ + // status: 404, + // success: false, + // message: "Data tidak ditemukan", + // }); + // } + + const data = await prisma.investasi.delete({ + where: { + id: id, + }, + }); + + const fixData = { + imageId: data.imageId, + prospektusFileId: data.prospektusFileId, + }; + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil Menghapus Data", + data: fixData, + }); + } catch (error) { + return NextResponse.json({ + status: 500, + success: false, + message: "Error Menghapus Data", + reason: (error as Error).message, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const { data } = await request.json(); + + console.log("[PUT INVESTASI]", id, data); + + const updateData = await prisma.investasi.update({ + where: { + id: id, + }, + data: { + authorId: data.authorId, + title: data.title, + targetDana: data.targetDana, + hargaLembar: data.hargaLembar, + totalLembar: data.totalLembar, + roi: data.roi, + masterPencarianInvestorId: data.masterPencarianInvestorId, + masterPeriodeDevidenId: data.masterPeriodeDevidenId, + masterPembagianDevidenId: data.masterPembagianDevidenId, + imageId: data.imageId, + + }, + }); + + console.log("[UPDATE INVESTASI]", updateData); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil Mengupdate Data", + data: updateData, + }); + } catch (error) { + return NextResponse.json({ + status: 500, + success: false, + message: "Error Mengupdate Data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/investment/route.ts b/src/app/api/mobile/investment/route.ts new file mode 100644 index 00000000..85d4ea12 --- /dev/null +++ b/src/app/api/mobile/investment/route.ts @@ -0,0 +1,46 @@ +import _ from "lodash"; +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { POST }; +async function POST(request: Request) { + const { data } = await request.json(); + console.log(["DATA INVESTASI"], data); + + try { + const create = await prisma.investasi.create({ + data: { + masterStatusInvestasiId: "2", + authorId: data.authorId, + title: _.startCase(data.title), + targetDana: data.targetDana, + hargaLembar: data.hargaLembar, + totalLembar: data.totalLembar, + sisaLembar: data.totalLembar, + roi: data.roi, + masterPencarianInvestorId: data.masterPencarianInvestorId, + masterPembagianDevidenId: data.masterPembagianDevidenId, + masterPeriodeDevidenId: data.masterPeriodeDevidenId, + imageId: data.imageId, + prospektusFileId: data.prospektusFileId, + }, + }); + + console.log("[CREATE INVESTASI]", create); + + return NextResponse.json({ + status: 201, + success: true, + message: "Berhasil Membuat Investasi", + }); + } catch (error) { + console.log("[ERROR CREATE INVESTASI]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error Membuat Investasi ", + reason: error || (error as Error).message, + }); + } +} +