mobile-notification done #46

Merged
bagasbanuna merged 2 commits from mobile-notification/27-jan-26 into staging 2026-01-27 17:00:27 +08:00
6 changed files with 137 additions and 28 deletions

View File

@@ -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.5.38](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.37...v1.5.38) (2026-01-27)
## [1.5.37](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.36...v1.5.37) (2026-01-23) ## [1.5.37](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.36...v1.5.37) (2026-01-23)
## [1.5.36](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.35...v1.5.36) (2026-01-13) ## [1.5.36](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.35...v1.5.36) (2026-01-13)

View File

@@ -1,6 +1,6 @@
{ {
"name": "hipmi", "name": "hipmi",
"version": "1.5.37", "version": "1.5.38",
"private": true, "private": true,
"prisma": { "prisma": {
"seed": "bun prisma/seed.ts" "seed": "bun prisma/seed.ts"

View File

@@ -1,11 +1,22 @@
import { funFindDonaturList } from "@/lib/mobile/donation/find-donatur-list";
import {
sendNotificationMobileToManyUser,
sendNotificationMobileToOneUser,
} from "@/lib/mobile/notification/send-notification";
import prisma from "@/lib/prisma"; import prisma from "@/lib/prisma";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../../../../types/type-mobile-notification";
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
export { POST, GET }; export { POST, GET };
async function POST(request: Request, { params }: { params: { id: string } }) { async function POST(request: Request, { params }: { params: { id: string } }) {
const { id } = params; const { id } = params;
const { data } = await request.json(); const { data } = await request.json();
const { title, nominalCair, deskripsi, imageId, authorId } = data;
try { try {
const dataDonasi = await prisma.donasi.findUnique({ const dataDonasi = await prisma.donasi.findUnique({
@@ -22,19 +33,19 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
return NextResponse.json( return NextResponse.json(
{ {
success: false, success: false,
message: "Pencarian Donasi Gagal", message: "DataPencarian Donasi Gagal",
reason: "Pencarian Donasi Gagal", reason: "Data Pencarian Donasi Gagal",
}, },
{ status: 400 } { status: 400 },
); );
const createPencairan = await prisma.donasi_PencairanDana.create({ const createPencairan = await prisma.donasi_PencairanDana.create({
data: { data: {
donasiId: id, donasiId: id,
nominalCair: +data.nominalCair, nominalCair: +nominalCair,
deskripsi: data.deskripsi, deskripsi: deskripsi,
title: data.title, title: title,
imageId: data.imageId, imageId: imageId,
}, },
}); });
@@ -45,11 +56,11 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
message: "Pencairan Dana Gagal", message: "Pencairan Dana Gagal",
reason: "Pencairan Dana Gagal", reason: "Pencairan Dana Gagal",
}, },
{ status: 400 } { status: 400 },
); );
const hasilTotalPencairan = const hasilTotalPencairan =
Number(dataDonasi.totalPencairan) + Number(data.nominalCair); Number(dataDonasi.totalPencairan) + Number(nominalCair);
// const hasilAkumulasiPencairan = Number(dataDonasi.akumulasiPencairan) + 1; // const hasilAkumulasiPencairan = Number(dataDonasi.akumulasiPencairan) + 1;
const countPencairan = await prisma.donasi_PencairanDana.count({ const countPencairan = await prisma.donasi_PencairanDana.count({
@@ -66,8 +77,47 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
akumulasiPencairan: countPencairan, akumulasiPencairan: countPencairan,
totalPencairan: hasilTotalPencairan, totalPencairan: hasilTotalPencairan,
}, },
select: {
authorId: true,
title: true,
},
}); });
// ================= START SEND NOTIFICATION =================
await sendNotificationMobileToOneUser({
recipientId: updateDonasi?.authorId!,
senderId: authorId,
payload: {
title: "Pencairan Dana Berhasil" as NotificationMobileTitleType,
body: `Telah dilaksanakan pencairan dana untuk ${updateDonasi?.title}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "DONASI",
deepLink: routeUserMobile.donationDetailPublish({
id: id,
}),
},
});
const recipientIds = await funFindDonaturList(id);
if (recipientIds.length > 0) {
await sendNotificationMobileToManyUser({
recipientIds,
senderId: authorId,
payload: {
title: "Pencarian Dana" as NotificationMobileTitleType,
body: `Update pencarian dana pada ${updateDonasi?.title}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "DONASI",
deepLink: routeUserMobile.donationDetailPublish({
id: id,
}),
},
});
}
// ================= END SEND NOTIFICATION =================
if (!updateDonasi) if (!updateDonasi)
return NextResponse.json( return NextResponse.json(
{ {
@@ -75,7 +125,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
message: "Update Donasi Gagal", message: "Update Donasi Gagal",
reason: "Update Donasi Gagal", reason: "Update Donasi Gagal",
}, },
{ status: 400 } { status: 400 },
); );
return NextResponse.json( return NextResponse.json(
@@ -84,7 +134,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
message: "Pencairan Dana Berhasil", message: "Pencairan Dana Berhasil",
// data: data, // data: data,
}, },
{ status: 200 } { status: 200 },
); );
} catch (error) { } catch (error) {
console.error("[ERROR]", error); console.error("[ERROR]", error);
@@ -94,7 +144,7 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
message: "Pencairan Dana Gagal", message: "Pencairan Dana Gagal",
reason: (error as Error).message, reason: (error as Error).message,
}, },
{ status: 500 } { status: 500 },
); );
} }
} }
@@ -110,7 +160,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
console.log("[CATEGORY]", category); console.log("[CATEGORY]", category);
let fixData; let fixData;
try { try {
if (category === "get-all") { if (category === "get-all") {
fixData = await prisma.donasi_PencairanDana.findMany({ fixData = await prisma.donasi_PencairanDana.findMany({
take: page ? takeData : undefined, take: page ? takeData : undefined,
@@ -140,7 +189,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
message: "Category tidak ditemukan", message: "Category tidak ditemukan",
reason: "Category tidak ditemukan", reason: "Category tidak ditemukan",
}, },
{ status: 400 } { status: 400 },
); );
} }
@@ -150,7 +199,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
message: "Success get data disbursement", message: "Success get data disbursement",
data: fixData, data: fixData,
}, },
{ status: 200 } { status: 200 },
); );
} catch (error) { } catch (error) {
console.error("[ERROR]", error); console.error("[ERROR]", error);
@@ -160,7 +209,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
message: "Gagal mendapatkan data disbursement", message: "Gagal mendapatkan data disbursement",
reason: (error as Error).message, reason: (error as Error).message,
}, },
{ status: 500 } { status: 500 },
); );
} }
} }

View File

@@ -1,25 +1,39 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib"; import { prisma } from "@/lib";
import _ from "lodash"; import _ from "lodash";
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../../../types/type-mobile-notification";
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
import { funFindDonaturList } from "@/lib/mobile/donation/find-donatur-list";
export { POST, GET, PUT, DELETE }; export { POST, GET, PUT, DELETE };
async function POST( async function POST(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: { id: string } },
) { ) {
const { id } = params; const { id } = params;
const { data } = await request.json(); const { data } = await request.json();
const { title, deskripsi, imageId } = data;
const senderId = await prisma.donasi.findUnique({
where: { id: id },
select: {
authorId: true,
},
});
try { try {
if (data && data?.imageId) { if (data && data?.imageId) {
const createWithFile = await prisma.donasi_Kabar.create({ const createWithFile = await prisma.donasi_Kabar.create({
data: { data: {
title: data.title, title: title,
deskripsi: data.deskripsi, deskripsi: deskripsi,
donasiId: id, donasiId: id,
imageId: data.imageId, imageId: imageId,
}, },
}); });
@@ -28,8 +42,8 @@ async function POST(
} else { } else {
const create = await prisma.donasi_Kabar.create({ const create = await prisma.donasi_Kabar.create({
data: { data: {
title: data.title, title: title,
deskripsi: data.deskripsi, deskripsi: deskripsi,
donasiId: id, donasiId: id,
}, },
}); });
@@ -38,6 +52,25 @@ async function POST(
return NextResponse.json({ status: 400, message: "Gagal disimpan" }); return NextResponse.json({ status: 400, message: "Gagal disimpan" });
} }
const recipientIds = await funFindDonaturList(id);
// SEND NOTIFICATION
if (recipientIds.length > 0) {
await sendNotificationMobileToManyUser({
recipientIds,
senderId: senderId?.authorId!,
payload: {
title: "Berita terbaru" as NotificationMobileTitleType,
body: `Ada berita terupdate pada ${title}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "DONASI",
deepLink: routeUserMobile.donationDetailPublish({
id: id,
}),
},
});
}
return NextResponse.json({ return NextResponse.json({
status: 200, status: 200,
success: true, success: true,
@@ -56,7 +89,7 @@ async function POST(
async function GET( async function GET(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: { id: string } },
) { ) {
const { id } = params; const { id } = params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
@@ -178,7 +211,7 @@ async function PUT(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;
try { try {
@@ -198,7 +231,7 @@ async function DELETE(
headers: { headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`, Authorization: `Bearer ${process.env.WS_APIKEY}`,
}, },
} },
); );
if (!deleteImage) { if (!deleteImage) {

View File

@@ -5,7 +5,7 @@ import { NextResponse } from "next/server";
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification"; import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile"; import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
export { POST }; export { POST, GET };
async function POST(request: Request) { async function POST(request: Request) {
const { data } = await request.json(); const { data } = await request.json();
@@ -121,7 +121,7 @@ async function POST(request: Request) {
} }
// GET ALL DATA DONASI // GET ALL DATA DONASI
export async function GET(request: Request) { async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const category = searchParams.get("category"); const category = searchParams.get("category");
const authorId = searchParams.get("authorId"); const authorId = searchParams.get("authorId");

View File

@@ -0,0 +1,25 @@
import prisma from "@/lib/prisma";
export const funFindDonaturList = async (donasiId: string) => {
const finDonatur = await prisma.donasi_Invoice.findMany({
where: {
donasiId: donasiId,
DonasiMaster_StatusInvoice: {
name: "Berhasil",
},
},
select: {
authorId: true,
},
distinct: ["authorId"], // Ambil hanya authorId unik dari DB
});
// Filter null safety (jika diperlukan)
const recipientIds = finDonatur
.map((e) => e.authorId)
.filter((id): id is string => id !== null && id !== undefined);
console.log("[FIND DONATUR UNIK]", recipientIds);
return recipientIds;
};