Merge pull request 'Mobile API: Investment' (#27) from mobile/2-oct-25 into staging
Reviewed-on: bip/hipmi#27
This commit is contained in:
@@ -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.
|
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.44](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.43...v1.4.44) (2025-10-02)
|
||||||
|
|
||||||
## [1.4.43](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.42...v1.4.43) (2025-09-29)
|
## [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.42](https://wibugit.wibudev.com/bip/hipmi/compare/v1.4.41...v1.4.42) (2025-09-24)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hipmi",
|
"name": "hipmi",
|
||||||
"version": "1.4.43",
|
"version": "1.4.44",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "bun prisma/seed.ts"
|
"seed": "bun prisma/seed.ts"
|
||||||
|
|||||||
215
src/app/api/mobile/investment/[id]/invoice/route.ts
Normal file
215
src/app/api/mobile/investment/[id]/invoice/route.ts
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
import { prisma } from "@/lib";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export { POST, GET, PUT };
|
||||||
|
|
||||||
|
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log("[ID INVOICE]", id);
|
||||||
|
console.log("[DATA INVOICE]", data);
|
||||||
|
|
||||||
|
const create = await prisma.investasi_Invoice.create({
|
||||||
|
data: {
|
||||||
|
investasiId: id,
|
||||||
|
authorId: data.authorId,
|
||||||
|
nominal: "" + data.total,
|
||||||
|
lembarTerbeli: "" + data.jumlah,
|
||||||
|
masterBankId: data.bankId,
|
||||||
|
statusInvoiceId: "3",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[CREATE INVOICE]", create);
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 201,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil membuat invoice",
|
||||||
|
data: create,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[ERROR CREATE INVOICE]", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal membuat invoice",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params; // << AUTHOR ID
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
const authorId = searchParams.get("authorId");
|
||||||
|
|
||||||
|
let fixData;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (category === "invoice") {
|
||||||
|
const data = await prisma.investasi_Invoice.findFirst({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
MasterBank: true,
|
||||||
|
StatusInvoice: true,
|
||||||
|
Investasi: {
|
||||||
|
include: {
|
||||||
|
MasterPembagianDeviden: true,
|
||||||
|
MasterPencarianInvestor: true,
|
||||||
|
MasterPeriodeDeviden: true,
|
||||||
|
ProspektusInvestasi: true,
|
||||||
|
Investasi_Invoice: {
|
||||||
|
where: {
|
||||||
|
statusInvoiceId: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Author: {
|
||||||
|
include: {
|
||||||
|
Profile: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ...allData } = data;
|
||||||
|
const Investor = data?.Investasi?.Investasi_Invoice;
|
||||||
|
fixData = { ...allData, Investor };
|
||||||
|
} else if (category == "my-invest") {
|
||||||
|
const data = await prisma.investasi_Invoice.findMany({
|
||||||
|
orderBy: {
|
||||||
|
updatedAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
authorId: authorId,
|
||||||
|
statusInvoiceId: "1",
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
nominal: true,
|
||||||
|
lembarTerbeli: true,
|
||||||
|
Investasi: {
|
||||||
|
select: {
|
||||||
|
title: true,
|
||||||
|
progress: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = data.map((v: any) => ({
|
||||||
|
..._.omit(v, ["Investasi"]),
|
||||||
|
title: v.Investasi.title,
|
||||||
|
progress: v.Investasi.progress,
|
||||||
|
}));
|
||||||
|
} else if (category == "transaction") {
|
||||||
|
const data = await prisma.investasi_Invoice.findMany({
|
||||||
|
orderBy: {
|
||||||
|
updatedAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
authorId: authorId,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
statusInvoiceId: true,
|
||||||
|
nominal: true,
|
||||||
|
createdAt: true,
|
||||||
|
StatusInvoice: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Investasi: {
|
||||||
|
select: {
|
||||||
|
title: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = data.map((v: any) => ({
|
||||||
|
..._.omit(v, ["Investasi", "StatusInvoice"]),
|
||||||
|
title: v.Investasi.title,
|
||||||
|
statusInvoice: v.StatusInvoice.name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: `Berhasil mendapatkan data ${category}`,
|
||||||
|
data: fixData,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error get ${category}`, error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: `Gagal mendapatkan data ${category}`,
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
const { id } = params;
|
||||||
|
const { data } = await request.json();
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const status = searchParams.get("status");
|
||||||
|
const fixStatus = _.startCase(status || "");
|
||||||
|
|
||||||
|
console.log("[FIX STATUS]", fixStatus);
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
console.log("[ID]", id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const checkStatus = await prisma.investasiMaster_StatusInvoice.findFirst({
|
||||||
|
where: {
|
||||||
|
name: fixStatus,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[CHECK STATUS]", checkStatus);
|
||||||
|
|
||||||
|
if (!checkStatus) {
|
||||||
|
throw new Error("Status invoice tidak ditemukan");
|
||||||
|
}
|
||||||
|
|
||||||
|
const update = await prisma.investasi_Invoice.update({
|
||||||
|
where: {
|
||||||
|
id: id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
statusInvoiceId: checkStatus.id,
|
||||||
|
imageId: data.imageId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[UPDATE]", update);
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 200,
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mengubah status invoice",
|
||||||
|
// data: update,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error update invoice", error);
|
||||||
|
return NextResponse.json({
|
||||||
|
status: 500,
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mengubah status invoice",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/app/api/mobile/master/bank/route.ts
Normal file
34
src/app/api/mobile/master/bank/route.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { prisma } from "@/lib";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export { GET };
|
||||||
|
|
||||||
|
async function GET() {
|
||||||
|
try {
|
||||||
|
const data = await prisma.masterBank.findMany({
|
||||||
|
orderBy: {
|
||||||
|
updatedAt: "asc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{ success: true, message: "Berhasil mendapatkan data", data: data },
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error Get Master Bank >>", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "API Error Get Data",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user