Compare commits
4 Commits
mobile-not
...
mobile-not
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a558cec8e | |||
| b9354cb6bf | |||
| 7cdde6b5a9 | |||
| e77e5eb3ac |
@@ -2,6 +2,10 @@
|
||||
|
||||
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,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.34",
|
||||
"version": "1.5.36",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
@@ -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 =========== //
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
sendNotificationMobileToOneUser,
|
||||
} from "@/lib/mobile/notification/send-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { NotificationMobileBodyType } from "../../../../../../../types/type-mobile-notification";
|
||||
import { NotificationMobileBodyType, NotificationMobileTitleType } from "../../../../../../../types/type-mobile-notification";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -110,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" }),
|
||||
@@ -143,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",
|
||||
@@ -160,7 +160,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: data.authorId,
|
||||
payload: {
|
||||
title: "Ada lowongan kerja baru",
|
||||
title: "Ada Lowongan Kerja Baru" as NotificationMobileTitleType,
|
||||
body: `${updt.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeUserMobile.jobDetailPublised({ id: id }),
|
||||
|
||||
@@ -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,23 @@ async function POST(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
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,
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 }
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -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 {
|
||||
@@ -77,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);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
@@ -9,12 +9,21 @@ const routeAdminMobile = {
|
||||
`/admin/job/${id}/${status}`,
|
||||
jobByStatus: ({ status }: { status: StatusApp }) =>
|
||||
`/admin/job/${status}/status`,
|
||||
|
||||
// EVENT
|
||||
eventByStatus: ({ status }: { status: StatusApp }) =>
|
||||
`/admin/event/${status}/status`,
|
||||
};
|
||||
|
||||
const routeUserMobile = {
|
||||
home: `/(user)/home`,
|
||||
// JOB
|
||||
jobDetailPublised: ({ id }: { id: string }) => `/job/${id}`,
|
||||
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`,
|
||||
};
|
||||
|
||||
@@ -13,18 +13,20 @@ export type NotificationMobilePayload = {
|
||||
|
||||
export type NotificationMobileTitleType =
|
||||
| (string & { __type: "NotificationMobileTitleType" })
|
||||
| "Pengajuan Review"
|
||||
// Admin
|
||||
| "Pengajuan Review Baru"
|
||||
// USER
|
||||
| "Pengajuan Review Ditolak"
|
||||
| "Review Selesai"
|
||||
// to ALL user
|
||||
| "Ada lowongan kerja baru"
|
||||
|
||||
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 =
|
||||
|
||||
Reference in New Issue
Block a user