refactor(invesment): penyesuaian endpoint admin, invoice, dan navigasi mobile
- src/app/api/mobile/admin/investment/[id]/route.ts - src/app/api/mobile/investment/[id]/invoice/route.ts - src/app/api/mobile/investment/route.ts - src/lib/mobile/route-page-mobile.ts ### No Issue
This commit is contained in:
@@ -1,11 +1,20 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import {
|
||||||
|
sendNotificationMobileToManyUser,
|
||||||
|
sendNotificationMobileToOneUser,
|
||||||
|
} from "@/lib/mobile/notification/send-notification";
|
||||||
|
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
import {
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
|
||||||
export { GET, PUT };
|
export { GET, PUT };
|
||||||
|
|
||||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await prisma.investasi.findUnique({
|
const data = await prisma.investasi.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@@ -78,14 +87,19 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
|
const { catatan, senderId } = data;
|
||||||
|
|
||||||
|
console.log("[DATA]", data);
|
||||||
|
console.log("[CATATAN]", catatan);
|
||||||
|
console.log("[SENDER ID]", senderId);
|
||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const status = searchParams.get("status");
|
const status = searchParams.get("status");
|
||||||
|
|
||||||
console.log("[=======Start Investment console=======]");
|
// console.log("[=======Start Investment console=======]");
|
||||||
console.log("[ID]", id);
|
// console.log("[ID]", id);
|
||||||
console.log("[DATA]", data);
|
// console.log("[STATUS]", status);
|
||||||
console.log("[STATUS]", status);
|
// console.log("[=======End Investment console=======]");
|
||||||
console.log("[=======End Investment console=======]");
|
|
||||||
|
|
||||||
const publishTime = new Date();
|
const publishTime = new Date();
|
||||||
|
|
||||||
@@ -96,9 +110,26 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
catatan: data,
|
catatan: catatan,
|
||||||
masterStatusInvestasiId: "4",
|
masterStatusInvestasiId: "4",
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
authorId: true,
|
||||||
|
title: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: updatedData.authorId as any,
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Pengajuan Review Ditolak",
|
||||||
|
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeUserMobile.investmentByStatus({ status: "reject" }),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[UPDATE REJECT]", updatedData);
|
console.log("[UPDATE REJECT]", updatedData);
|
||||||
@@ -114,6 +145,41 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICAtION
|
||||||
|
await sendNotificationMobileToOneUser({
|
||||||
|
recipientId: updatedData.authorId as any,
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Review Selesai",
|
||||||
|
body: `
|
||||||
|
Investasi kamu telah dipublikasikan !\n
|
||||||
|
${updatedData.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeUserMobile.investmentByStatus({ status: "publish" }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const allUsers = await prisma.user.findMany({
|
||||||
|
where: {
|
||||||
|
NOT: { id: updatedData.authorId as any },
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendNotificationMobileToManyUser({
|
||||||
|
recipientIds: allUsers.map((user) => user.id),
|
||||||
|
senderId: senderId,
|
||||||
|
payload: {
|
||||||
|
title: "Ayo Cek Investasi Terbaru" as NotificationMobileTitleType,
|
||||||
|
body: `${updatedData.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeUserMobile.investasiDetailPublish({ id: id }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
console.log("[UPDATE PUBLISH]", updatedData);
|
console.log("[UPDATE PUBLISH]", updatedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import {
|
||||||
|
NotificationMobileTitleType,
|
||||||
|
NotificationMobileBodyType,
|
||||||
|
} from "../../../../../../../types/type-mobile-notification";
|
||||||
|
|
||||||
export { POST, GET, PUT };
|
export { POST, GET, PUT };
|
||||||
|
|
||||||
@@ -49,7 +55,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
|||||||
const authorId = searchParams.get("authorId");
|
const authorId = searchParams.get("authorId");
|
||||||
|
|
||||||
console.log("[ID INVOICE]", id);
|
console.log("[ID INVOICE]", id);
|
||||||
|
|
||||||
|
|
||||||
let fixData;
|
let fixData;
|
||||||
|
|
||||||
@@ -198,8 +203,45 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
statusInvoiceId: checkStatus.id,
|
statusInvoiceId: checkStatus.id,
|
||||||
imageId: data.imageId,
|
imageId: data.imageId,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
investasiId: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (fixStatus === "Proses") {
|
||||||
|
// kirim notif ke author investasi
|
||||||
|
const findInvestasi = await prisma.investasi.findUnique({
|
||||||
|
where: {
|
||||||
|
id: update.investasiId as any,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
title: true,
|
||||||
|
authorId: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const findUsers = await prisma.user.findMany({
|
||||||
|
where: {
|
||||||
|
masterUserRoleId: "2",
|
||||||
|
active: true,
|
||||||
|
NOT: { id: findInvestasi?.authorId as any },
|
||||||
|
},
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendNotificationMobileToManyUser({
|
||||||
|
recipientIds: findUsers.map((user) => user.id),
|
||||||
|
senderId: data.authorId,
|
||||||
|
payload: {
|
||||||
|
title: "Ada Investor Baru !" as NotificationMobileTitleType,
|
||||||
|
body: `Cek data investor pada ${findInvestasi?.title}` as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
deepLink: routeAdminMobile.investmentByStatus({ status: "publish" }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log("[UPDATE]", update);
|
console.log("[UPDATE]", update);
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import _ from "lodash";
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||||
|
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||||
|
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||||
|
|
||||||
export { POST, GET };
|
export { POST, GET };
|
||||||
|
|
||||||
@@ -9,12 +12,14 @@ async function POST(request: Request) {
|
|||||||
const { data } = await request.json();
|
const { data } = await request.json();
|
||||||
console.log(["DATA INVESTASI"], data);
|
console.log(["DATA INVESTASI"], data);
|
||||||
|
|
||||||
|
const fixTitle = _.startCase(data.title)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const create = await prisma.investasi.create({
|
const create = await prisma.investasi.create({
|
||||||
data: {
|
data: {
|
||||||
masterStatusInvestasiId: "2",
|
masterStatusInvestasiId: "2",
|
||||||
authorId: data.authorId,
|
authorId: data.authorId,
|
||||||
title: _.startCase(data.title),
|
title: fixTitle,
|
||||||
targetDana: data.targetDana,
|
targetDana: data.targetDana,
|
||||||
hargaLembar: data.hargaLembar,
|
hargaLembar: data.hargaLembar,
|
||||||
totalLembar: data.totalLembar,
|
totalLembar: data.totalLembar,
|
||||||
@@ -30,6 +35,24 @@ async function POST(request: Request) {
|
|||||||
|
|
||||||
console.log("[CREATE INVESTASI]", create);
|
console.log("[CREATE INVESTASI]", create);
|
||||||
|
|
||||||
|
const adminUsers = await prisma.user.findMany({
|
||||||
|
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
// SEND NOTIFICATION
|
||||||
|
await sendNotificationMobileToManyUser({
|
||||||
|
recipientIds: adminUsers.map((user) => user.id),
|
||||||
|
senderId: data.authorId,
|
||||||
|
payload: {
|
||||||
|
title: "Pengajuan Review Baru",
|
||||||
|
body: fixTitle as NotificationMobileBodyType,
|
||||||
|
type: "announcement",
|
||||||
|
deepLink: routeAdminMobile.investmentByStatus({ status: "review" }),
|
||||||
|
kategoriApp: "INVESTASI",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: 201,
|
status: 201,
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ const routeAdminMobile = {
|
|||||||
// FORUM
|
// FORUM
|
||||||
forumPreviewReportPosting: `/admin/forum/report-posting`,
|
forumPreviewReportPosting: `/admin/forum/report-posting`,
|
||||||
forumPreviewReportComment: `/admin/forum/report-comment`,
|
forumPreviewReportComment: `/admin/forum/report-comment`,
|
||||||
|
|
||||||
|
// INVESTMENT
|
||||||
|
investmentByStatus: ({ status }: { status: StatusApp }) =>
|
||||||
|
`/admin/investment/${status}/status`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const routeUserMobile = {
|
const routeUserMobile = {
|
||||||
@@ -41,6 +45,13 @@ const routeUserMobile = {
|
|||||||
// FORUM
|
// FORUM
|
||||||
forumBeranda: `/forum`,
|
forumBeranda: `/forum`,
|
||||||
forumDetail: ({ id }: { id: string }) => `/forum/${id}`,
|
forumDetail: ({ id }: { id: string }) => `/forum/${id}`,
|
||||||
forumPreviewReportPosting: ({ id }: { id: string }) => `/forum/${id}/preview-report-posting`,
|
forumPreviewReportPosting: ({ id }: { id: string }) =>
|
||||||
forumPreviewReportComment: ({ id }: { id: string }) => `/forum/${id}/preview-report-comment`,
|
`/forum/${id}/preview-report-posting`,
|
||||||
|
forumPreviewReportComment: ({ id }: { id: string }) =>
|
||||||
|
`/forum/${id}/preview-report-comment`,
|
||||||
|
|
||||||
|
// INVESTMENT
|
||||||
|
investmentByStatus: ({ status }: { status?: StatusApp }) =>
|
||||||
|
`/investment/(tabs)/portofolio?status=${status}`,
|
||||||
|
investasiDetailPublish: ({ id }: { id: string }) => `/investment/${id}`,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user