Merge pull request 'fix: error send notification' (#28) from amalia/28-agustus-25 into join
Reviewed-on: bip/sistem-desa-mandiri#28
This commit is contained in:
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
return NextResponse.json({ success: true, version: "1.7.4", tahap: "beta", update: "-api mobile; -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi" }, { status: 200 });
|
||||
return NextResponse.json({ success: true, version: "1.7.5", tahap: "beta", update: "-api mobile; -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
@@ -8,23 +8,27 @@ WibuServerPush.init({
|
||||
|
||||
export async function funSendWebPush({ sub, message }: { sub: { idUser: string, subscription: string }[], message: { body: string, title: string } }) {
|
||||
try {
|
||||
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
||||
if (sub.length > 0) {
|
||||
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
||||
|
||||
const kirim = await WibuServerPush.sendMany({
|
||||
subscriptions: subs as any,
|
||||
data: {
|
||||
body: message.body,
|
||||
title: message.title,
|
||||
link: "/home?cat=notification",
|
||||
variant: "notification"
|
||||
const kirim = await WibuServerPush.sendMany({
|
||||
subscriptions: subs as any,
|
||||
data: {
|
||||
body: message.body,
|
||||
title: message.title,
|
||||
link: "/home?cat=notification",
|
||||
variant: "notification"
|
||||
}
|
||||
})
|
||||
|
||||
if (kirim) {
|
||||
return { success: true, message: "Berhasil mengirim notifikasi" }
|
||||
}
|
||||
})
|
||||
|
||||
if (kirim) {
|
||||
return { success: true, message: "Berhasil mengirim notifikasi" }
|
||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||
}
|
||||
|
||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||
return { success: true, message: "Berhasil mengirim notifikasi [0]" }
|
||||
} catch (error) {
|
||||
console.error("Send web push notification error", error);
|
||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||
|
||||
@@ -43,8 +43,10 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
||||
},
|
||||
},
|
||||
};
|
||||
console.log("masuk", token.length, token)
|
||||
|
||||
if (token.length > 0) {
|
||||
console.log("Token", token.length)
|
||||
// Kirim pesan
|
||||
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||
if (response.failureCount > 0) {
|
||||
|
||||
Reference in New Issue
Block a user