Compare commits

..

27 Commits

Author SHA1 Message Date
d09e30c049 Voting notifikasi for mobile
Fix:
- src/app/api/mobile/admin/voting/[id]/route.ts
- src/app/api/mobile/event/route.ts
- src/app/api/mobile/voting/[id]/route.ts
- src/app/api/mobile/voting/route.ts
- src/lib/mobile/route-page-mobile.ts

### No Issue
2026-01-15 17:38:33 +08:00
c8bd928c33 Fix notifikasi join dari event
Fix:
 modified:   src/app/api/mobile/event/[id]/participants/route.ts
        modified:   src/bin/seeder/user_seeder.json

### No Issue
2026-01-15 13:57:00 +08:00
3a558cec8e chore(release): 1.5.36 2026-01-13 17:45:58 +08:00
b9354cb6bf Penerapan notifikasi pada event
Fix:
- src/app/api/mobile/admin/event/[id]/route.ts
- src/app/api/mobile/admin/job/[id]/route.ts
- src/app/api/mobile/event/route.ts
- src/app/api/mobile/job/route.ts
- src/app/api/mobile/notification/[id]/route.ts
- src/lib/mobile/notification/send-notification.ts
- src/lib/mobile/route-page-mobile.ts
- types/type-mobile-notification.ts

### No Issue
2026-01-13 17:45:37 +08:00
7cdde6b5a9 chore(release): 1.5.35 2026-01-12 17:35:50 +08:00
e77e5eb3ac Fix notification reuse component
Fix:
- modified:   src/app/api/auth/mobile-register/route.ts
- modified:   src/lib/mobile/notification/send-notification.ts

### No Issue
2026-01-12 17:35:27 +08:00
8f3f27122a chore(release): 1.5.34 2026-01-09 17:45:54 +08:00
d84a1d84ff Fix route untuk penambahan fitur EULA
Fix:
- modified:   src/app/api/auth/mobile-login/route.ts

Add:
- src/app/api/auth/mobile-eula/

### No Issue
2026-01-09 17:45:44 +08:00
40ba31edec Fix mobile notification:
- Bug penerima pesan 2 kali

Fix:
modified:   src/lib/mobile/notification/send-notification.ts

### No Issue
2026-01-09 14:42:45 +08:00
a54f8599b4 API Mobile notifikasi job
Fix:
modified:   src/app/api/mobile/admin/job/[id]/route.ts
modified:   src/app/api/mobile/job/[id]/route.ts
modified:   src/app/api/mobile/job/route.ts
modified:   src/lib/mobile/route-page-mobile.ts
modified:   types/type-mobile-notification.ts

### No Issue
2026-01-08 18:35:32 +08:00
09825756f3 Merge branch 'mobile-notification/7-jan-26' of https://wibugit.wibudev.com/wibu/hipmi into mobile-notification/8-jan-26 2026-01-08 10:35:49 +08:00
3552cf4f39 Merge pull request 'mobile-notification API' (#36) from mobile-notification/24-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/36
2025-12-24 17:48:07 +08:00
d207b6feed Merge pull request 'Penerapan notifikasi mobile' (#35) from mobile-notification/19-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/35
2025-12-19 16:40:09 +08:00
f1c8432fdc Merge pull request 'Fix DB table donasi' (#33) from login-api/17-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/33
2025-12-17 14:44:53 +08:00
1cd4c3713e Merge pull request 'login-api/17-dec-25' (#31) from login-api/17-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/31
2025-12-17 11:43:32 +08:00
4307b383e3 Merge pull request 'Penerapan notifikasi mobil ke database' (#30) from mobile-notification/16-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/30
2025-12-16 17:57:21 +08:00
0786d23336 Merge pull request 'API notif dan penambahan package firebase-admin' (#29) from mobile-notification/15-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/29
2025-12-15 17:52:03 +08:00
cb3511f973 Merge pull request 'Fix QC ( Ayu )' (#28) from qc-mobile/10-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/28
2025-12-10 17:38:42 +08:00
b4921c4e82 Merge pull request 'Fix API untuk QC: Ayu' (#27) from qc-mobile/9-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/27
2025-12-09 17:40:20 +08:00
a9325054eb Merge pull request 'Fix Apple Reject' (#26) from qc-mobile/8-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/26
2025-12-08 15:33:58 +08:00
819812149f Merge pull request 'Fix QC Admin ( Inno )' (#25) from qc-mobile/5-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/25
2025-12-05 17:15:53 +08:00
75ba2b29ae Merge pull request 'Fix QC Inno:' (#24) from mobile-reject/4-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/24
2025-12-04 17:45:04 +08:00
54a4d15bdd Merge pull request 'Fix WA Server' (#23) from mobile-reject/3-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/23
2025-12-03 16:28:09 +08:00
1321f33da9 Merge pull request 'Fix Apple Rejected' (#22) from mobile-reject/3-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/22
2025-12-03 15:02:40 +08:00
fad0c33b9a Merge pull request 'Alur autentikasi dirubah' (#21) from mobile-reject/2-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/21
2025-12-02 14:41:44 +08:00
565bab4998 Merge pull request 'QC Mobile: Pak jun dan Inno' (#20) from qc/1-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/20
2025-12-01 17:44:48 +08:00
7530a38c4d Merge pull request 'Fix version' (#19) from apple-reject/28-nov-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/19
2025-11-28 11:47:44 +08:00
19 changed files with 507 additions and 238 deletions

View File

@@ -2,6 +2,12 @@
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.36](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.35...v1.5.36) (2026-01-13)
## [1.5.35](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.34...v1.5.35) (2026-01-12)
## [1.5.34](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.33...v1.5.34) (2026-01-09)
## [1.5.33](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.32...v1.5.33) (2026-01-06)
## [1.5.32](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.31...v1.5.32) (2026-01-05)

View File

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

View File

@@ -0,0 +1,54 @@
import { prisma } from "@/lib";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
try {
const { nomor } = await req.json();
const user = await prisma.user.findUnique({
where: {
nomor: nomor,
},
});
if (!user)
return NextResponse.json({
success: false,
message: "User belum terdaftar",
status: 404,
});
const updateTerms = await prisma.user.update({
where: { nomor: nomor },
data: {
termsOfServiceAccepted: true,
acceptedTermsAt: new Date(),
},
});
if (!updateTerms) {
return NextResponse.json({
success: false,
message: "Gagal setujui syarat dan ketentuan",
status: 400,
});
}
return NextResponse.json(
{
success: true,
message: "Anda telah setujui syarat dan ketentuan",
},
{ status: 200 }
);
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Terjadi masalah saat setujui syarat dan ketentuan",
reason: error as Error,
},
{ status: 500 }
);
}
}

View File

@@ -6,7 +6,6 @@ export async function POST(req: Request) {
try {
const codeOtp = randomOTP();
const body = await req.json();
console.log("[Masuk API]", body);
const { nomor } = body;
const user = await prisma.user.findUnique({
@@ -15,9 +14,6 @@ export async function POST(req: Request) {
},
});
console.log(["cek user", user]);
console.log(["cek nomor", nomor]);
if (!user)
return NextResponse.json({
success: false,
@@ -66,6 +62,7 @@ export async function POST(req: Request) {
success: true,
message: "Kode verifikasi terkirim",
kodeId: createOtpId.id,
isAcceptTerms: user.termsOfServiceAccepted,
},
{ status: 200 }
);

View File

@@ -1,8 +1,12 @@
import { sessionCreate } from "@/app/(auth)/_lib/session_create";
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
import { adminMessaging } from "@/lib/firebase-admin";
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../types/type-mobile-notification";
export async function POST(req: Request) {
if (req.method !== "POST") {
@@ -84,12 +88,12 @@ export async function POST(req: Request) {
// =========== START SEND NOTIFICATION =========== //
const findAllUserBySendTo = await prisma.user.findMany({
where: { masterUserRoleId: "2" },
const adminUsers = await prisma.user.findMany({
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
select: { id: true },
});
console.log("Users to notify:", findAllUserBySendTo);
console.log("Users to notify:", adminUsers);
const dataNotification = {
title: "Pendaftaran Baru",
@@ -101,63 +105,17 @@ export async function POST(req: Request) {
senderId: createUser.id,
};
for (let a of findAllUserBySendTo) {
const createdNotification = await prisma.notifikasi.create({
data: {
...dataNotification,
recipientId: a.id,
},
});
if (createdNotification) {
const deviceToken = await prisma.tokenUserDevice.findMany({
where: {
userId: a.id,
isActive: true,
},
});
for (let i of deviceToken) {
const message = {
token: i.token,
notification: {
title: dataNotification.title,
body: dataNotification.pesan,
},
data: {
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
id: createdNotification.id,
deepLink: dataNotification.deepLink,
},
// Konfigurasi Android untuk prioritas tinggi
android: {
priority: "high" as const, // Kirim secepatnya, bahkan di doze mode untuk notifikasi penting
notification: {
channelId: "default", // Sesuaikan dengan channel yang kamu buat di Android
},
ttl: 0 as const, // Kirim secepatnya, jangan tunda
},
// Opsional: tambahkan untuk iOS juga
apns: {
payload: {
aps: {
sound: "default" as const,
// 'content-available': 1 as const, // jika butuh silent push
},
},
},
};
try {
const response = await adminMessaging.send(message);
console.log("✅ FCM sent successfully", "Response:", response);
} catch (error: any) {
console.error("❌ FCM send failed:", error);
// Lanjutkan ke token berikutnya meski satu gagal
}
}
}
}
await sendNotificationMobileToManyUser({
recipientIds: adminUsers.map((user) => user.id),
senderId: data.authorId,
payload: {
title: "Pendaftaran User Baru" as NotificationMobileTitleType,
body: "User baru telah melakukan registrasi. Ayo cek dan verifikasi!" as NotificationMobileBodyType,
type: "announcement",
deepLink: routeAdminMobile.userAccess({ id: createUser.id }),
kategoriApp: "OTHER",
},
});
// =========== END SEND NOTIFICATION =========== //

View File

@@ -1,6 +1,15 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
import {
sendNotificationMobileToManyUser,
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 };
@@ -57,6 +66,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
const { catatan, senderId } = data;
const { searchParams } = new URL(request.url);
const status = searchParams.get("status");
const fixStatus = _.startCase(status as string);
@@ -89,11 +100,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
id: id,
},
data: {
catatan: data,
catatan: catatan,
eventMaster_StatusId: checkStatus.id,
},
});
await sendNotificationMobileToOneUser({
recipientId: updateData.authorId as any,
senderId: senderId,
payload: {
title: "Pengajuan Review Ditolak",
body: "Mohon perbaiki data sesuai catatan penolakan !",
type: "announcement",
kategoriApp: "EVENT",
deepLink: routeUserMobile.eventByStatus({status: "reject"}),
},
});
fixData = updateData;
} else if (fixStatus === "Publish") {
const updateData = await prisma.event.update({
@@ -105,6 +128,38 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
});
await sendNotificationMobileToOneUser({
recipientId: updateData.authorId as any,
senderId: senderId,
payload: {
title: "Review Selesai",
body: "Event kamu telah dipublikasikan !" as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "EVENT",
deepLink: routeUserMobile.eventByStatus({status: "publish"}),
},
});
const adminUsers = await prisma.user.findMany({
where: {
masterUserRoleId: "1",
NOT: { id: updateData.authorId as any },
},
select: { id: true },
});
await sendNotificationMobileToManyUser({
recipientIds: adminUsers.map((user) => user.id),
senderId: senderId,
payload: {
title: "Event Baru" as NotificationMobileTitleType,
body: `${updateData.title}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "EVENT",
deepLink: routeUserMobile.eventDetailPublised({ id: id }),
},
});
fixData = updateData;
}

View File

@@ -1,8 +1,12 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
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 };
@@ -63,7 +67,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
const status = searchParams.get("status");
const fixStatus = _.startCase(status as string);
let fixData;
try {
const checkStatus = await prisma.masterStatus.findFirst({
@@ -107,8 +110,8 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
recipientId: updt.authorId as any,
senderId: senderId,
payload: {
title: "Pengajuan Review",
body: "Pengajuan data anda telah di tolak !",
title: "Pengajuan Review Ditolak",
body: "Mohon perbaiki data sesuai catatan penolakan !",
type: "announcement",
kategoriApp: "JOB",
deepLink: routeUserMobile.jobByStatus({ status: "reject" }),
@@ -140,7 +143,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
recipientId: updt.authorId as any,
senderId: senderId,
payload: {
title: "Pengajuan Review",
title: "Review Selesai",
body: "Selamat data anda telah terpublikasi",
type: "announcement",
kategoriApp: "JOB",
@@ -148,6 +151,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
});
const adminUsers = await prisma.user.findMany({
where: { masterUserRoleId: "1", NOT: { id: updt.authorId as any } },
select: { id: true },
});
await sendNotificationMobileToManyUser({
recipientIds: adminUsers.map((user) => user.id),
senderId: data.authorId,
payload: {
title: "Ada Lowongan Kerja Baru" as NotificationMobileTitleType,
body: `${updt.title}` as NotificationMobileBodyType,
type: "announcement",
deepLink: routeUserMobile.jobDetailPublised({ id: id }),
kategoriApp: "JOB",
},
});
fixData = updt;
}

View File

@@ -1,8 +1,17 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib";
import _ from "lodash";
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 } }) {
const { id } = params;
@@ -41,12 +50,16 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
async function PUT(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
const { catatan, senderId } = data;
console.log("catatan", catatan);
console.log("senderId", senderId);
const { searchParams } = new URL(request.url);
const status = searchParams.get("status");
const fixStatus = _.startCase(status as string);
let fixData;
try {
const checkStatus = await prisma.voting_Status.findFirst({
where: {
@@ -71,9 +84,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
data: {
voting_StatusId: checkStatus.id,
catatan: data,
catatan: catatan,
},
});
// SEND NOTIFICATION
await sendNotificationMobileToOneUser({
recipientId: updateStatus.authorId as any,
senderId: senderId,
payload: {
title: "Pengajuan Review Ditolak",
body: "Mohon perbaiki data sesuai catatan penolakan !",
type: "announcement",
kategoriApp: "VOTING",
deepLink: routeUserMobile.votingByStatus({ status: "reject" }),
},
});
fixData = updateStatus;
} else if (fixStatus === "Publish") {
const updateStatus = await prisma.voting.update({
@@ -84,6 +111,39 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
voting_StatusId: checkStatus.id,
},
});
await sendNotificationMobileToOneUser({
recipientId: updateStatus.authorId as any,
senderId: senderId,
payload: {
title: "Review Selesai",
body: "Voting kamu telah dipublikasikan !" as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "VOTING",
deepLink: routeUserMobile.votingByStatus({ status: "publish" }),
},
});
const adminUsers = await prisma.user.findMany({
where: {
masterUserRoleId: "1",
NOT: { id: updateStatus.authorId as any },
},
select: { id: true },
});
await sendNotificationMobileToManyUser({
recipientIds: adminUsers.map((user) => user.id),
senderId: senderId,
payload: {
title: "Cek Voting Baru Terpublikasi" as NotificationMobileTitleType,
body: `${updateStatus.title}` as NotificationMobileBodyType,
type: "announcement",
kategoriApp: "VOTING",
deepLink: routeUserMobile.votingDetailPublised({ id: id }),
},
});
fixData = updateStatus;
}

View File

@@ -1,5 +1,11 @@
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import {
NotificationMobileBodyType,
NotificationMobileTitleType,
} from "../../../../../../../types/type-mobile-notification";
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
export { GET, POST };
@@ -13,18 +19,28 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
eventId: id,
userId: userId,
},
// select: {
// Event: {
// select: {
// id: true,
// title: true,
// authorId: true,
// },
// },
// },
});
const findEvent = await prisma.event.findUnique({
where: { id: id },
select: { authorId: true, title: true },
});
// SEND NOTIFICATION
if (userId !== findEvent?.authorId) {
await sendNotificationMobileToOneUser({
recipientId: findEvent?.authorId as string,
senderId: userId,
payload: {
title: "Peserta Baru Join" as NotificationMobileTitleType,
body: `Ada peserta baru dalam event: ${findEvent?.title}` as NotificationMobileBodyType,
type: "announcement",
deepLink: routeUserMobile.eventDetailPublised({ id: id }),
kategoriApp: "EVENT",
},
});
}
return NextResponse.json(
{
success: true,

View File

@@ -1,7 +1,10 @@
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
import prisma from "@/lib/prisma";
import _ from "lodash";
import moment from "moment";
import { NextResponse } from "next/server";
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
export { GET, POST };
@@ -30,6 +33,24 @@ async function POST(request: Request) {
},
});
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: create.title as NotificationMobileBodyType,
type: "announcement",
deepLink: routeAdminMobile.eventByStatus({ status: "review" }),
kategoriApp: "EVENT",
},
});
return NextResponse.json(
{
success: true,

View File

@@ -13,6 +13,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
include: {
Author: {
select: {
id: true,
username: true,
nomor: true,
Profile: {

View File

@@ -2,6 +2,7 @@ import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
export { POST, GET };
@@ -22,7 +23,7 @@ async function POST(request: Request) {
// kirim notifikasi ke semua admin untuk mengetahui ada job baru yang harus di review
const adminUsers = await prisma.user.findMany({
where: { masterUserRoleId: "2" },
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
select: { id: true },
});
@@ -30,8 +31,8 @@ async function POST(request: Request) {
recipientIds: adminUsers.map((user) => user.id),
senderId: data.authorId,
payload: {
title: "Pengajuan Review",
body: "Terdapat pengajuan baru yang perlu direview",
title: "Pengajuan Review Baru",
body: `${create.title}` as NotificationMobileBodyType,
type: "announcement",
deepLink: routeAdminMobile.jobByStatus({ status: "review" }),
kategoriApp: "JOB",

View File

@@ -45,23 +45,38 @@ export async function PUT(
{ params }: { params: { id: string } }
) {
const { id } = params;
const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
try {
await prisma.notifikasi.update({
where: {
id: id,
},
data: {
isRead: true,
readAt: new Date(),
},
});
if (category === "one") {
await prisma.notifikasi.update({
where: {
id: id,
},
data: {
isRead: true,
readAt: new Date(),
},
});
} else if (category === "all") {
await prisma.notifikasi.updateMany({
where: {
recipientId: id,
},
data: {
isRead: true,
readAt: new Date(),
},
});
}
return NextResponse.json({
success: true,
message: "Notifications marked as read",
});
} catch (error) {
console.error("Error marking notifications as read:", error);
return NextResponse.json(
{ error: (error as Error).message },
{ status: 500 }
@@ -69,129 +84,129 @@ export async function PUT(
}
}
export async function POST(
request: NextRequest,
{ params }: { params: { id: string } }
) {
const { id } = params;
// export async function POST(
// request: NextRequest,
// { params }: { params: { id: string } }
// ) {
// const { id } = params;
const { data } = await request.json();
// const { data } = await request.json();
const {
title,
body: notificationBody,
userLoginId,
type,
kategoriApp,
appId,
status,
deepLink,
} = data as NotificationProp;
// const {
// title,
// body: notificationBody,
// userLoginId,
// type,
// kategoriApp,
// appId,
// status,
// deepLink,
// } = data as NotificationProp;
console.log("Notification Send >>", data);
// console.log("Notification Send >>", data);
try {
// Cari user yang login
const findUserLogin = await prisma.user.findUnique({
where: {
id: userLoginId,
},
});
// try {
// // Cari user yang login
// const findUserLogin = await prisma.user.findUnique({
// where: {
// id: userLoginId,
// },
// });
if (!findUserLogin) {
return NextResponse.json({ error: "User not found" }, { status: 404 });
}
// if (!findUserLogin) {
// return NextResponse.json({ error: "User not found" }, { status: 404 });
// }
// Cari token fcm user yang login
const checkFcmToken = await prisma.tokenUserDevice.findFirst({
where: {
userId: findUserLogin.id,
},
});
// // Cari token fcm user yang login
// const checkFcmToken = await prisma.tokenUserDevice.findFirst({
// where: {
// userId: findUserLogin.id,
// },
// });
if (!checkFcmToken) {
return NextResponse.json(
{ error: "FCM Token not found" },
{ status: 404 }
);
}
// if (!checkFcmToken) {
// return NextResponse.json(
// { error: "FCM Token not found" },
// { status: 404 }
// );
// }
const created = await prisma.notifikasi.create({
data: {
title,
type,
createdAt: new Date(),
appId,
kategoriApp,
pesan: notificationBody || "",
userRoleId: findUserLogin.masterUserRoleId,
status,
deepLink,
senderId: findUserLogin.id,
recipientId: id,
},
});
// const created = await prisma.notifikasi.create({
// data: {
// title,
// type,
// createdAt: new Date(),
// appId,
// kategoriApp,
// pesan: notificationBody || "",
// userRoleId: findUserLogin.masterUserRoleId,
// status,
// deepLink,
// senderId: findUserLogin.id,
// recipientId: id,
// },
// });
if (created) {
const deviceToken = await prisma.tokenUserDevice.findMany({
where: {
userId: id,
isActive: true,
},
});
// if (created) {
// const deviceToken = await prisma.tokenUserDevice.findMany({
// where: {
// userId: id,
// isActive: true,
// },
// });
for (let i of deviceToken) {
const message = {
token: i.token,
notification: {
title,
body: notificationBody || "",
},
data: {
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
id: created.id,
deepLink: deepLink || "",
},
// Konfigurasi Android untuk prioritas tinggi
android: {
priority: "high" as const, // Kirim secepatnya, bahkan di doze mode untuk notifikasi penting
notification: {
channelId: "default", // Sesuaikan dengan channel yang kamu buat di Android
},
// for (let i of deviceToken) {
// const message = {
// token: i.token,
// notification: {
// title,
// body: notificationBody || "",
// },
// data: {
// sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
// id: created.id,
// deepLink: deepLink || "",
// },
// // Konfigurasi Android untuk prioritas tinggi
// android: {
// priority: "high" as const, // Kirim secepatnya, bahkan di doze mode untuk notifikasi penting
// notification: {
// channelId: "default", // Sesuaikan dengan channel yang kamu buat di Android
// },
ttl: 0 as const, // Kirim secepatnya, jangan tunda
},
// Opsional: tambahkan untuk iOS juga
apns: {
payload: {
aps: {
sound: "default" as const,
// 'content-available': 1 as const, // jika butuh silent push
},
},
},
};
// ttl: 0 as const, // Kirim secepatnya, jangan tunda
// },
// // Opsional: tambahkan untuk iOS juga
// apns: {
// payload: {
// aps: {
// sound: "default" as const,
// // 'content-available': 1 as const, // jika butuh silent push
// },
// },
// },
// };
try {
const response = await adminMessaging.send(message);
console.log("✅ FCM sent successfully", "Response:", response);
} catch (error: any) {
console.error("❌ FCM send failed:", error);
// Lanjutkan ke token berikutnya meski satu gagal
}
}
}
// try {
// const response = await adminMessaging.send(message);
// console.log("✅ FCM sent successfully", "Response:", response);
// } catch (error: any) {
// console.error("❌ FCM send failed:", error);
// // Lanjutkan ke token berikutnya meski satu gagal
// }
// }
// }
return NextResponse.json({
success: true,
message: "Notification sent successfully",
});
} catch (error) {
console.error("❌ FCM error:", error);
// return NextResponse.json({
// success: true,
// message: "Notification sent successfully",
// });
// } catch (error) {
// console.error("❌ FCM error:", error);
return NextResponse.json(
{ error: (error as Error).message },
{ status: 500 }
);
}
}
// return NextResponse.json(
// { error: (error as Error).message },
// { status: 500 }
// );
// }
// }

View File

@@ -1,6 +1,12 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
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, DELETE, PUT, POST };
@@ -39,7 +45,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
const listNamaVote = data?.Voting_DaftarNamaVote || [];
for (let v of listNamaVote) {
const kontributor = await prisma.voting_Kontributor.findMany({
where: {
voting_DaftarNamaVoteId: v.id,
@@ -90,7 +95,6 @@ async function DELETE(
},
});
return NextResponse.json({
success: true,
message: "Berhasil menghapus data",
@@ -171,7 +175,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
},
});
if (!updateVoting)
return NextResponse.json({ status: 400, message: "Gagal Update" });
}
@@ -193,11 +196,12 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
async function POST(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { data } = await request.json();
const { chooseId, userId } = data;
try {
const findData = await prisma.voting_DaftarNamaVote.findFirst({
const findDatapilihan = await prisma.voting_DaftarNamaVote.findFirst({
where: {
id: data.chooseId,
id: chooseId,
},
select: {
jumlah: true,
@@ -205,28 +209,32 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
},
});
if (!findData)
if (!findDatapilihan)
return NextResponse.json({
success: false,
message: "Data tidak ditemukan",
});
const updateData = await prisma.voting_DaftarNamaVote.update({
const updateDataPilihan = await prisma.voting_DaftarNamaVote.update({
where: {
id: data.chooseId,
},
data: {
jumlah: findData.jumlah + 1,
jumlah: findDatapilihan.jumlah + 1,
},
});
if (!updateData)
if (!updateDataPilihan)
return NextResponse.json({
success: false,
message: "Gagal Update Data",
});
const findVotingData = await prisma.voting.findUnique({
where: { id: id },
select: { authorId: true, title: true },
});
const createKontributor = await prisma.voting_Kontributor.create({
data: {
votingId: id,
@@ -250,6 +258,21 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
message: "Gagal Menjadi Kontributor",
});
// SEND NOTIFICATION
if (userId !== findVotingData?.authorId) {
await sendNotificationMobileToOneUser({
recipientId: findVotingData?.authorId as string,
senderId: userId,
payload: {
title: "User Melakukan Vote" as NotificationMobileTitleType,
body: `Salah satu user telah melakukan voting pada: ${findVotingData?.title}` as NotificationMobileBodyType,
type: "announcement",
deepLink: routeUserMobile.votingDetailPublised({ id: id }),
kategoriApp: "VOTING",
},
});
}
return NextResponse.json({
success: true,
message: "Berhasil Voting",

View File

@@ -1,6 +1,9 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import _ from "lodash";
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 };
@@ -41,6 +44,24 @@ async function POST(request: Request) {
});
}
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: create.title as NotificationMobileBodyType,
type: "announcement",
deepLink: routeAdminMobile.votingByStatus({ status: "review" }),
kategoriApp: "VOTING",
},
});
return NextResponse.json(
{
success: true,
@@ -125,8 +146,6 @@ async function GET(request: Request) {
});
fixData = data;
} else if (category === "contribution") {
const data = await prisma.voting_Kontributor.findMany({
orderBy: {

View File

@@ -1,13 +1,13 @@
[
{
"name": "default_user",
"name": "demo_user",
"nomor": "6282340374412",
"masterUserRoleId": "1",
"active": true,
"termsOfServiceAccepted": false
},
{
"name": "admin_911",
"name": "demo_admin",
"nomor": "6281339158911",
"masterUserRoleId": "3",
"active": true,

View File

@@ -22,7 +22,10 @@ export async function sendNotificationMobileToOneUser({
}) {
try {
const kategoriToNormalCase = _.lowerCase(payload.kategoriApp);
const titleFix = `${_.startCase(kategoriToNormalCase)}: ${payload.title}`;
const titleFix =
kategoriToNormalCase === "other"
? payload.title
: `${_.startCase(kategoriToNormalCase)}: ${payload.title}`;
console.log("titleFix", titleFix);
// 1. Simpan notifikasi ke DB
@@ -40,7 +43,7 @@ export async function sendNotificationMobileToOneUser({
// 2. Ambil semua token aktif milik penerima
const tokens = await prisma.tokenUserDevice.findMany({
where: { userId: recipientId, isActive: true },
where: { userId: recipientId },
select: { token: true, id: true },
});
@@ -50,7 +53,6 @@ export async function sendNotificationMobileToOneUser({
}
// 3. Kirim FCM ke semua token
await Promise.allSettled(
tokens.map(async ({ token, id }) => {
try {
@@ -64,6 +66,7 @@ export async function sendNotificationMobileToOneUser({
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
id: notification.id,
deepLink: payload.deepLink,
recipientId: recipientId,
},
android: {
priority: "high" as const,
@@ -76,12 +79,11 @@ export async function sendNotificationMobileToOneUser({
});
} catch (fcmError: any) {
// Hapus token jika invalid
console.log("fcmError", fcmError);
if (fcmError.code === "messaging/invalid-registration-token") {
await prisma.tokenUserDevice.delete({ where: { id: id } });
console.log(` Invalid token removed: ${token}`);
if (fcmError.code === "messaging/registration-token-not-registered") {
// Hapus token dari DB
await prisma.tokenUserDevice.delete({ where: { id } });
console.log(`🗑️ Invalid token removed: ${id}`);
}
console.error(`FCM failed for token ${token}:`, fcmError.message);
}
})
);

View File

@@ -5,10 +5,16 @@ type StatusApp = "review" | "draft" | "reject" | "publish";
const routeAdminMobile = {
userAccess: ({ id }: { id: string }) => `/admin/user-access/${id}`,
// JOB
jobDetail: ({ id, status }: { id: string; status: StatusApp }) =>
`/admin/job/${id}/${status}`,
jobByStatus: ({ status }: { status: StatusApp }) =>
`/admin/job/${status}/status`,
// EVENT
eventByStatus: ({ status }: { status: StatusApp }) =>
`/admin/event/${status}/status`,
// VOTING
votingByStatus: ({ status }: { status: StatusApp }) =>
`/admin/voting/${status}/status`,
};
const routeUserMobile = {
@@ -16,4 +22,15 @@ const routeUserMobile = {
// JOB
jobByStatus: ({ status }: { status?: StatusApp }) =>
`/job/(tabs)/status?status=${status}`,
jobDetailPublised: ({ id }: { id: string }) => `/job/${id}`,
// EVENT
eventByStatus: ({ status }: { status?: StatusApp }) =>
`/event/(tabs)/status?status=${status}`,
eventDetailPublised: ({ id }: { id: string }) => `/event/${id}/publish`,
// VOTING
votingByStatus: ({ status }: { status?: StatusApp }) =>
`/voting/(tabs)/status?status=${status}`,
votingDetailPublised: ({ id }: { id: string }) => `/voting/${id}`,
};

View File

@@ -13,16 +13,20 @@ export type NotificationMobilePayload = {
export type NotificationMobileTitleType =
| (string & { __type: "NotificationMobileTitleType" })
| "Pengajuan Review"
| "Review Selesai";
// Admin
| "Pengajuan Review Baru"
// USER
| "Pengajuan Review Ditolak"
| "Review Selesai"
// to ALL user
export type NotificationMobileBodyType =
// USER
| (string & { __type: "NotificationMobileBodyType" })
| "Terdapat pengajuan baru yang perlu direview"
| "Ada pengajuan review" // tambah title
// ADMIN
| "Pengajuan data anda telah di tolak !"
| "Mohon perbaiki data sesuai catatan penolakan !"
| "Selamat data anda telah terpublikasi"
export type TypeNotificationCategoryApp =