API – Investment (Admin & User)
- src/app/api/mobile/admin/investment/[id]/route.ts - src/app/api/mobile/admin/investment/[id]/invoice/route.ts - src/app/api/mobile/investment/[id]/invoice/route.ts - src/app/api/mobile/investment/[id]/document/route.ts Routing Helper - src/lib/mobile/route-page-mobile.ts ### No Issue
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../../../types/type-mobile-notification";
|
||||||
|
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
|
||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
@@ -65,19 +71,39 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
|
|||||||
data: {
|
data: {
|
||||||
statusInvoiceId: "4",
|
statusInvoiceId: "4",
|
||||||
},
|
},
|
||||||
// select: {
|
select: {
|
||||||
// StatusInvoice: true,
|
Investasi: {
|
||||||
// authorId: true,
|
select: {
|
||||||
// },
|
title: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
authorId: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICAtION
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: updt?.authorId as string,
|
||||||
|
senderId: data?.senderId || "",
|
||||||
|
payload: {
|
||||||
|
title: "Transaksi Tertolak" as NotificationMobileTitleType,
|
||||||
|
body: `Maaf transaksi kamu telah ditolak ! ${updt?.Investasi?.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeUserMobile.investasiTransaction,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
fixData = updt;
|
fixData = updt;
|
||||||
} else if (category === "accept") {
|
} else if (category === "accept") {
|
||||||
const dataInvestasi: any = await prisma.investasi.findFirst({
|
const findInvestasi = await prisma.investasi.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: data.investasiId,
|
id: data.investasiId,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
authorId: true,
|
||||||
totalLembar: true,
|
totalLembar: true,
|
||||||
sisaLembar: true,
|
sisaLembar: true,
|
||||||
lembarTerbeli: true,
|
lembarTerbeli: true,
|
||||||
@@ -85,30 +111,33 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Hitung TOTAL SISA LEMBAR
|
// Hitung TOTAL SISA LEMBAR
|
||||||
const investasi_sisaLembar = Number(dataInvestasi?.sisaLembar);
|
const investasi_sisaLembar = Number(findInvestasi?.sisaLembar);
|
||||||
const invoice_lembarTerbeli = Number(data.lembarTerbeli);
|
const invoice_lembarTerbeli = Number(data.lembarTerbeli);
|
||||||
const resultSisaLembar = investasi_sisaLembar - invoice_lembarTerbeli;
|
const resultSisaLembar = investasi_sisaLembar - invoice_lembarTerbeli;
|
||||||
|
|
||||||
// TAMBAH LEMBAR TERBELI
|
// TAMBAH LEMBAR TERBELI
|
||||||
const investasi_lembarTerbeli = Number(dataInvestasi?.lembarTerbeli);
|
const investasi_lembarTerbeli = Number(findInvestasi?.lembarTerbeli);
|
||||||
const resultLembarTerbeli =
|
const resultLembarTerbeli =
|
||||||
investasi_lembarTerbeli + invoice_lembarTerbeli;
|
investasi_lembarTerbeli + invoice_lembarTerbeli;
|
||||||
|
|
||||||
// Progress
|
// Progress
|
||||||
const investasi_totalLembar = Number(dataInvestasi?.totalLembar);
|
const investasi_totalLembar = Number(findInvestasi?.totalLembar);
|
||||||
const progress = (resultLembarTerbeli / investasi_totalLembar) * 100;
|
const progress = (resultLembarTerbeli / investasi_totalLembar) * 100;
|
||||||
const resultProgres = Number(progress).toFixed(2);
|
const resultProgres = Number(progress).toFixed(2);
|
||||||
|
|
||||||
const updt = await prisma.investasi_Invoice.update({
|
const updateInvoice = await prisma.investasi_Invoice.update({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
statusInvoiceId: "1",
|
statusInvoiceId: "1",
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
authorId: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!updt) {
|
if (!updateInvoice) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
@@ -144,7 +173,35 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fixData = updt;
|
// SEND NOTIFICATION: to investor
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: updateInvoice?.authorId as string,
|
||||||
|
senderId: data?.senderId || "",
|
||||||
|
payload: {
|
||||||
|
title: "Transaksi Berhasil" as NotificationMobileTitleType,
|
||||||
|
body: `Selamat anda menjadi investor pada investasi ${findInvestasi?.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeUserMobile.investasiTransaction,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION: to creator
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: findInvestasi?.authorId as any,
|
||||||
|
senderId: data?.senderId || "",
|
||||||
|
payload: {
|
||||||
|
title: "Ada Investor Baru !" as NotificationMobileTitleType,
|
||||||
|
body: `Cek daftar investor pada ${findInvestasi?.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeUserMobile.investasiDetailPublish({
|
||||||
|
id: findInvestasi?.id as string,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = updateInvoice;
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
||||||
type: "announcement",
|
type: "announcement",
|
||||||
kategoriApp: "INVESTASI",
|
kategoriApp: "INVESTASI",
|
||||||
deepLink: routeUserMobile.investmentByStatus({ status: "reject" }),
|
deepLink: routeUserMobile.investmentPortofolioByStatus({ status: "reject" }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -151,12 +151,10 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
senderId: senderId,
|
senderId: senderId,
|
||||||
payload: {
|
payload: {
|
||||||
title: "Review Selesai",
|
title: "Review Selesai",
|
||||||
body: `
|
body: `Investasi kamu telah dipublikasikan ! ${updatedData.title}` as NotificationMobileBodyType,
|
||||||
Investasi kamu telah dipublikasikan !\n
|
|
||||||
${updatedData.title}` as NotificationMobileBodyType,
|
|
||||||
type: "announcement",
|
type: "announcement",
|
||||||
kategoriApp: "INVESTASI",
|
kategoriApp: "INVESTASI",
|
||||||
deepLink: routeUserMobile.investmentByStatus({ status: "publish" }),
|
deepLink: routeUserMobile.investmentPortofolioByStatus({ status: "publish" }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
|
||||||
export { POST, GET, DELETE };
|
export { POST, GET, DELETE };
|
||||||
|
|
||||||
@@ -10,7 +15,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
console.log("[POST DOCUMENT DATA]", data);
|
console.log("[POST DOCUMENT DATA]", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const create = await prisma.dokumenInvestasi.upsert({
|
const createdDocs = await prisma.dokumenInvestasi.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
@@ -23,9 +28,42 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
|||||||
title: data.title,
|
title: data.title,
|
||||||
fileId: data.fileId,
|
fileId: data.fileId,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
investasiId: true,
|
||||||
|
investasi: {
|
||||||
|
select: {
|
||||||
|
title: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!create)
|
const findInvestor = await prisma.investasi_Invoice.findMany({
|
||||||
|
where: {
|
||||||
|
investasiId: id,
|
||||||
|
StatusInvoice: {
|
||||||
|
name: "Berhasil",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
// await sendNotificationMobileToManyUser({
|
||||||
|
// recipientIds: findInvestor.map((user) => user.id),
|
||||||
|
// senderId: data.authorId,
|
||||||
|
// payload: {
|
||||||
|
// title: "Cek Dokumen" as NotificationMobileTitleType,
|
||||||
|
// body: `Ada informasi dokumen yang di\\\ ${createdDocs.investasi?.title}` as NotificationMobileBodyType,
|
||||||
|
// type: "announcement",
|
||||||
|
// kategoriApp: "INVESTASI",
|
||||||
|
// deepLink: routeAdminMobile.investmentDetailPublish({
|
||||||
|
// id: update.investasiId as string,
|
||||||
|
// status: "publish",
|
||||||
|
// }),
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
if (!createdDocs)
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: 201,
|
status: 201,
|
||||||
success: true,
|
success: true,
|
||||||
@@ -93,7 +131,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
|
|
||||||
async function DELETE(
|
async function DELETE(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: { id: string } },
|
||||||
) {
|
) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
|
||||||
@@ -111,7 +149,7 @@ async function DELETE(
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@@ -204,8 +204,8 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
imageId: data.imageId,
|
imageId: data.imageId,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
investasiId: true
|
investasiId: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fixStatus === "Proses") {
|
if (fixStatus === "Proses") {
|
||||||
@@ -229,6 +229,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
select: { id: true },
|
select: { id: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
await sendNotificationMobileToManyUser({
|
await sendNotificationMobileToManyUser({
|
||||||
recipientIds: findUsers.map((user) => user.id),
|
recipientIds: findUsers.map((user) => user.id),
|
||||||
senderId: data.authorId,
|
senderId: data.authorId,
|
||||||
@@ -237,7 +238,10 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
body: `Cek data investor pada ${findInvestasi?.title}` as NotificationMobileBodyType,
|
body: `Cek data investor pada ${findInvestasi?.title}` as NotificationMobileBodyType,
|
||||||
type: "announcement",
|
type: "announcement",
|
||||||
kategoriApp: "INVESTASI",
|
kategoriApp: "INVESTASI",
|
||||||
deepLink: routeAdminMobile.investmentByStatus({ status: "publish" }),
|
deepLink: routeAdminMobile.investmentDetailPublish({
|
||||||
|
id: update.investasiId as string,
|
||||||
|
status: "publish",
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,14 @@ const routeAdminMobile = {
|
|||||||
forumPreviewReportComment: `/admin/forum/report-comment`,
|
forumPreviewReportComment: `/admin/forum/report-comment`,
|
||||||
|
|
||||||
// INVESTMENT
|
// INVESTMENT
|
||||||
investmentByStatus: ({ status }: { status: StatusApp }) =>
|
investmentByStatus: ({ status }: { status: StatusApp }) => `/admin/investment/${status}/status`,
|
||||||
`/admin/investment/${status}/status`,
|
investmentDetailPublish: ({
|
||||||
|
id,
|
||||||
|
status,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
status: StatusApp;
|
||||||
|
}) => `/admin/investment/${id}/${status}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const routeUserMobile = {
|
const routeUserMobile = {
|
||||||
@@ -51,7 +57,8 @@ const routeUserMobile = {
|
|||||||
`/forum/${id}/preview-report-comment`,
|
`/forum/${id}/preview-report-comment`,
|
||||||
|
|
||||||
// INVESTMENT
|
// INVESTMENT
|
||||||
investmentByStatus: ({ status }: { status?: StatusApp }) =>
|
investmentPortofolioByStatus: ({ status }: { status?: StatusApp }) =>
|
||||||
`/investment/(tabs)/portofolio?status=${status}`,
|
`/investment/(tabs)/portofolio?status=${status}`,
|
||||||
investasiDetailPublish: ({ id }: { id: string }) => `/investment/${id}`,
|
investasiDetailPublish: ({ id }: { id: string }) => `/investment/${id}`,
|
||||||
|
investasiTransaction: `/investment/(tabs)/transaction`
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user