Notification investasi mobile done

### No Issue
This commit is contained in:
2026-01-22 17:53:35 +08:00
parent 20d05c1cc7
commit fc23e01275
7 changed files with 120 additions and 35 deletions

View File

@@ -90,7 +90,7 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
body: `Maaf transaksi kamu telah ditolak ! ${updt?.Investasi?.title}` as NotificationMobileBodyType, body: `Maaf transaksi kamu telah ditolak ! ${updt?.Investasi?.title}` as NotificationMobileBodyType,
type: "announcement", type: "announcement",
kategoriApp: "INVESTASI", kategoriApp: "INVESTASI",
deepLink: routeUserMobile.investasiTransaction, deepLink: routeUserMobile.investmentTransaction,
}, },
}); });
@@ -182,7 +182,7 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
body: `Selamat anda menjadi investor pada investasi ${findInvestasi?.title}` as NotificationMobileBodyType, body: `Selamat anda menjadi investor pada investasi ${findInvestasi?.title}` as NotificationMobileBodyType,
type: "announcement", type: "announcement",
kategoriApp: "INVESTASI", kategoriApp: "INVESTASI",
deepLink: routeUserMobile.investasiTransaction, deepLink: routeUserMobile.investmentTransaction,
}, },
}); });
@@ -195,7 +195,7 @@ async function PUT(req: Request, { params }: { params: { id: string } }) {
body: `Cek daftar investor pada ${findInvestasi?.title}` as NotificationMobileBodyType, body: `Cek daftar investor pada ${findInvestasi?.title}` as NotificationMobileBodyType,
type: "announcement", type: "announcement",
kategoriApp: "INVESTASI", kategoriApp: "INVESTASI",
deepLink: routeUserMobile.investasiDetailPublish({ deepLink: routeUserMobile.investmentDetailPublish({
id: findInvestasi?.id as string, id: findInvestasi?.id as string,
}), }),
}, },

View File

@@ -174,7 +174,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
body: `${updatedData.title}` as NotificationMobileBodyType, body: `${updatedData.title}` as NotificationMobileBodyType,
type: "announcement", type: "announcement",
kategoriApp: "INVESTASI", kategoriApp: "INVESTASI",
deepLink: routeUserMobile.investasiDetailPublish({ id: id }), deepLink: routeUserMobile.investmentDetailPublish({ id: id }),
}, },
}); });

View File

@@ -5,6 +5,7 @@ import {
NotificationMobileBodyType, NotificationMobileBodyType,
NotificationMobileTitleType, NotificationMobileTitleType,
} from "../../../../../../../types/type-mobile-notification"; } from "../../../../../../../types/type-mobile-notification";
import { routeAdminMobile, routeUserMobile } from "@/lib/mobile/route-page-mobile";
export { POST, GET, DELETE }; export { POST, GET, DELETE };
@@ -33,11 +34,14 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
investasi: { investasi: {
select: { select: {
title: true, title: true,
authorId: true,
}, },
}, },
}, },
}); });
console.log("[CREATED DOCS]", createdDocs);
const findInvestor = await prisma.investasi_Invoice.findMany({ const findInvestor = await prisma.investasi_Invoice.findMany({
where: { where: {
investasiId: id, investasiId: id,
@@ -45,23 +49,27 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
name: "Berhasil", name: "Berhasil",
}, },
}, },
select: {
authorId: true,
},
}); });
console.log("[FIND INVESTOR]", findInvestor);
// SEND NOTIFICATION // SEND NOTIFICATION
// await sendNotificationMobileToManyUser({ await sendNotificationMobileToManyUser({
// recipientIds: findInvestor.map((user) => user.id), recipientIds: findInvestor.map((e) => e.authorId!),
// senderId: data.authorId, senderId: createdDocs.investasi?.authorId as string,
// payload: { payload: {
// title: "Cek Dokumen" as NotificationMobileTitleType, title: "Cek Dokumen" as NotificationMobileTitleType,
// body: `Ada informasi dokumen yang di\\\ ${createdDocs.investasi?.title}` as NotificationMobileBodyType, body: `Ada dokumen terupdate pada ${createdDocs.investasi?.title}` as NotificationMobileBodyType,
// type: "announcement", type: "announcement",
// kategoriApp: "INVESTASI", kategoriApp: "INVESTASI",
// deepLink: routeAdminMobile.investmentDetailPublish({ deepLink: routeUserMobile.investmentDetailPublish({
// id: update.investasiId as string, id: createdDocs.investasiId as string,
// status: "publish", }),
// }), },
// }, });
// });
if (!createdDocs) if (!createdDocs)
return NextResponse.json({ return NextResponse.json({

View File

@@ -1,6 +1,7 @@
import _ from "lodash"; import _ from "lodash";
import { prisma } from "@/lib"; import { prisma } from "@/lib";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { sendNotificationInvestmentAddNews } from "@/lib/mobile/notification/notification-add-news-investment";
export { POST, GET, DELETE }; export { POST, GET, DELETE };
@@ -21,6 +22,21 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
deskripsi: data.deskripsi, deskripsi: data.deskripsi,
imageId: data.imageId, imageId: data.imageId,
}, },
select: {
investasiId: true,
investasi: {
select: {
title: true,
authorId: true,
},
},
},
});
await sendNotificationInvestmentAddNews({
invesmentId: createWithFile.investasiId,
senderId: createWithFile.investasi.authorId as string,
title: createWithFile.investasi.title,
}); });
fixData = createWithFile; fixData = createWithFile;
@@ -31,6 +47,21 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
title: _.startCase(data.title), title: _.startCase(data.title),
deskripsi: data.deskripsi, deskripsi: data.deskripsi,
}, },
select: {
investasiId: true,
investasi: {
select: {
title: true,
authorId: true,
},
},
},
});
await sendNotificationInvestmentAddNews({
invesmentId: createWitOutFile.investasiId,
senderId: createWitOutFile.investasi.authorId as string,
title: createWitOutFile.investasi.title,
}); });
fixData = createWitOutFile; fixData = createWitOutFile;
@@ -111,7 +142,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;
console.log("id", id); console.log("id", id);

View File

@@ -5,22 +5,22 @@ const sendCodeOtp = async ({
nomor: string; nomor: string;
codeOtp: string; codeOtp: string;
}) => { }) => {
// const msg = `HIPMI%20-%20Kode%20ini%20bersifat%20RAHASIA%20dan%20JANGAN%20DI%20BAGIKAN%20KEPADA%20SIAPAPUN%2C%20termasuk%20anggota%20ataupun%20pengurus%20HIPMI%20lainnya.%20Kode%20OTP%20anda%3A%20${codeOtp}.`; const msg = `HIPMI%20-%20Kode%20ini%20bersifat%20RAHASIA%20dan%20JANGAN%20DI%20BAGIKAN%20KEPADA%20SIAPAPUN%2C%20termasuk%20anggota%20ataupun%20pengurus%20HIPMI%20lainnya.%20Kode%20OTP%20anda%3A%20${codeOtp}.`;
// const res = await fetch(
// `https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${msg}`,
// {
// cache: "no-cache",
// headers: {
// Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
// },
// }
// );
const res = await fetch( const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya. `https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${msg}`,
\n {
>> Kode OTP anda: ${codeOtp}. cache: "no-cache",
`, headers: {
Authorization: `Bearer ${process.env.WA_SERVER_TOKEN}`,
},
},
); );
// const res = await fetch(
// `https://wa.wibudev.com/code?nom=${nomor}&text=HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.
// \n
// >> Kode OTP anda: ${codeOtp}.
// `,
// );
return res; return res;
}; };

View File

@@ -0,0 +1,46 @@
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../types/type-mobile-notification";
import { sendNotificationMobileToManyUser } from "./send-notification";
import { routeUserMobile } from "../route-page-mobile";
import prisma from "@/lib/prisma";
export const sendNotificationInvestmentAddNews = async ({
invesmentId,
senderId,
title,
}: {
invesmentId: string;
senderId: string;
title: string;
}) => {
const findInvestor = await prisma.investasi_Invoice.findMany({
where: {
investasiId: invesmentId,
StatusInvoice: {
name: "Berhasil",
},
},
select: {
authorId: true,
},
});
console.log("[FIND INVESTOR]", findInvestor);
// SEND NOTIFICATION
await sendNotificationMobileToManyUser({
recipientIds: findInvestor.map((e) => e.authorId!),
senderId: senderId,
payload: {
title: "Berita terbaru" as NotificationMobileTitleType,
body: `Ada berita yang terupdate pada ${title}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "INVESTASI",
deepLink: routeUserMobile.investmentDetailPublish({
id: invesmentId,
}),
},
});
};

View File

@@ -59,6 +59,6 @@ const routeUserMobile = {
// INVESTMENT // INVESTMENT
investmentPortofolioByStatus: ({ status }: { status?: StatusApp }) => investmentPortofolioByStatus: ({ status }: { status?: StatusApp }) =>
`/investment/(tabs)/portofolio?status=${status}`, `/investment/(tabs)/portofolio?status=${status}`,
investasiDetailPublish: ({ id }: { id: string }) => `/investment/${id}`, investmentDetailPublish: ({ id }: { id: string }) => `/investment/${id}`,
investasiTransaction: `/investment/(tabs)/transaction` investmentTransaction: `/investment/(tabs)/transaction`
}; };