upd: penerapan firebase
Deskripsi: - pengumuman - diskusi umum - diskusi divisi - divisi - kegiatan - tugas divisi No Issues
This commit is contained in:
@@ -175,8 +175,8 @@ export async function POST(request: Request) {
|
|||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TokenDeviceUser:{
|
TokenDeviceUser: {
|
||||||
select:{
|
select: {
|
||||||
token: true
|
token: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,8 +228,8 @@ export async function POST(request: Request) {
|
|||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TokenDeviceUser:{
|
TokenDeviceUser: {
|
||||||
select:{
|
select: {
|
||||||
token: true
|
token: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +255,6 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||||
|
|
||||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Pengumuman Baru', body: 'Anda memiliki pengumuman baru. Silahkan periksa detailnya.' } })
|
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Pengumuman Baru', body: 'Anda memiliki pengumuman baru. Silahkan periksa detailnya.' } })
|
||||||
@@ -263,7 +262,7 @@ export async function POST(request: Request) {
|
|||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|
||||||
const tokenUnique = [...new Set(tokenDup)];
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
await sendFCMNotificationMany({
|
await sendFCMNotificationMany({
|
||||||
token: tokenUnique,
|
token: tokenUnique,
|
||||||
title: "Pengumuman Baru",
|
title: "Pengumuman Baru",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import _ from "lodash";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import "moment/locale/id";
|
import "moment/locale/id";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendFCMNotificationMany } from "../../../../../xsendMany";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -141,6 +142,29 @@ export async function POST(request: Request) {
|
|||||||
data: dataMember
|
data: dataMember
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const memberNotifMobile = await prisma.discussionMember.findMany({
|
||||||
|
where: {
|
||||||
|
idDiscussion: data.id
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataFCM = memberNotifMobile.map((v: any) => ({
|
||||||
|
..._.omit(v, ["User", "TokenDeviceUser"]),
|
||||||
|
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||||
|
|
||||||
const dataNotif = member.map((v: any) => ({
|
const dataNotif = member.map((v: any) => ({
|
||||||
..._.omit(v, ["idUser", "name", "img"]),
|
..._.omit(v, ["idUser", "name", "img"]),
|
||||||
idUserTo: v.idUser,
|
idUserTo: v.idUser,
|
||||||
@@ -164,10 +188,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: perbekel?.id,
|
idUserTo: perbekel?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -182,6 +213,14 @@ export async function POST(request: Request) {
|
|||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
|
await sendFCMNotificationMany({
|
||||||
|
token: tokenUnique,
|
||||||
|
title: "Diskusi Umum Baru",
|
||||||
|
body: "Anda memiliki diskusi umum baru. Silahkan periksa detailnya.",
|
||||||
|
data: { id: data.id, category: "discussion", content: data.id }
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data diskusi umum', table: 'discussion', data: data.id, user })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data diskusi umum', table: 'discussion', data: data.id, user })
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { funSendWebPush, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import "moment/locale/id";
|
import "moment/locale/id";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendFCMNotificationMany } from "../../../../../xsendMany";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DISCUSSION DIVISION ACTIVE = TRUE
|
// GET ALL DISCUSSION DIVISION ACTIVE = TRUE
|
||||||
@@ -143,6 +144,11 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,10 +157,17 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
|
|
||||||
// mengirim notifikasi
|
// mengirim notifikasi
|
||||||
|
// dataFCM untuk push notifikasi mobile
|
||||||
// datanotif untuk realtime notifikasi
|
// datanotif untuk realtime notifikasi
|
||||||
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
||||||
|
const dataFCM = memberDivision.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||||
|
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||||
|
|
||||||
const dataNotif = memberDivision.map((v: any) => ({
|
const dataNotif = memberDivision.map((v: any) => ({
|
||||||
..._.omit(v, ["User", "Subscribe"]),
|
..._.omit(v, ["User", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUserTo: v.User.id,
|
idUserTo: v.User.id,
|
||||||
idUserFrom: String(userId),
|
idUserFrom: String(userId),
|
||||||
category: 'division/' + idDivision + '/discussion',
|
category: 'division/' + idDivision + '/discussion',
|
||||||
@@ -164,7 +177,7 @@ export async function POST(request: Request) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
const dataPush = memberDivision.map((v: any) => ({
|
const dataPush = memberDivision.map((v: any) => ({
|
||||||
..._.omit(v, ["User", "Subscribe"]),
|
..._.omit(v, ["User", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUser: v.User.id,
|
idUser: v.User.id,
|
||||||
subscription: v.User.Subscribe?.subscription,
|
subscription: v.User.Subscribe?.subscription,
|
||||||
}))
|
}))
|
||||||
@@ -182,10 +195,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: perbekel?.id,
|
idUserTo: perbekel?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -214,10 +234,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(ketuaGrup?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: ketuaGrup?.id,
|
idUserTo: ketuaGrup?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -235,11 +262,20 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||||
|
|
||||||
// const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { body: 'Terdapat diskusi baru. Silahkan periksa detailnya.', title: 'Diskusi Baru' } })
|
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { body: 'Terdapat diskusi baru. Silahkan periksa detailnya.', title: 'Diskusi Baru' } })
|
||||||
const insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
|
|
||||||
|
await sendFCMNotificationMany({
|
||||||
|
token: tokenUnique,
|
||||||
|
title: "Diskusi Baru",
|
||||||
|
body: "Anda memiliki diskusi baru. Silahkan periksa detailnya.",
|
||||||
|
data: { id: data.id, category: "division/" + idDivision + "/discussion", content: data.id }
|
||||||
|
})
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data diskusi', table: 'divisionDisscussion', data: data.id, user: userId })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data diskusi', table: 'divisionDisscussion', data: data.id, user: userId })
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { funSendWebPush, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendFCMNotificationMany } from "../../../../../xsendMany";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DATA DIVISI == LIST DATA DIVISI
|
// GET ALL DATA DIVISI == LIST DATA DIVISI
|
||||||
@@ -172,6 +173,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
|
|
||||||
// mengirim notifikasi
|
// mengirim notifikasi
|
||||||
|
// dataFCM untuk push notifikasi mobile
|
||||||
// datanotif untuk realtime notifikasi
|
// datanotif untuk realtime notifikasi
|
||||||
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
||||||
const dataNotif = sent.member.map((v: any) => ({
|
const dataNotif = sent.member.map((v: any) => ({
|
||||||
@@ -197,12 +199,23 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const dataFCM = selectUser.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||||
|
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||||
|
|
||||||
const dataPush = selectUser.map((v: any) => ({
|
const dataPush = selectUser.map((v: any) => ({
|
||||||
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
||||||
idUser: v.idUser,
|
idUser: v.idUser,
|
||||||
@@ -222,10 +235,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: perbekel?.id,
|
idUserTo: perbekel?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -258,12 +278,22 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const omitFCM = atasanGroup.map((v: any) => ({
|
||||||
|
..._.omit(v, ["id", "Subscribe", "TokenDeviceUser"]),
|
||||||
|
tokens: v.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
|
||||||
const omitData = atasanGroup.map((v: any) => ({
|
const omitData = atasanGroup.map((v: any) => ({
|
||||||
..._.omit(v, ["id", "Subscribe"]),
|
..._.omit(v, ["id", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUserTo: v.id,
|
idUserTo: v.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
category: 'division',
|
category: 'division',
|
||||||
@@ -273,24 +303,31 @@ export async function POST(request: Request) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
const omitPush = atasanGroup.map((v: any) => ({
|
const omitPush = atasanGroup.map((v: any) => ({
|
||||||
..._.omit(v, ["id", "Subscribe"]),
|
..._.omit(v, ["id", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUser: v.id,
|
idUser: v.id,
|
||||||
subscription: v.Subscribe?.subscription,
|
subscription: v.Subscribe?.subscription,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
dataNotif.push(...omitData)
|
dataNotif.push(...omitData)
|
||||||
dataPush.push(...omitPush)
|
dataPush.push(...omitPush)
|
||||||
|
tokenDup.push(...omitFCM.map((v: any) => v.tokens).flat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||||
|
|
||||||
// const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Divisi Baru', body: 'Terdapat divisi baru. Silahkan periksa detailnya.' } })
|
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Divisi Baru', body: 'Terdapat divisi baru. Silahkan periksa detailnya.' } })
|
||||||
const insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
|
await sendFCMNotificationMany({
|
||||||
|
token: tokenUnique,
|
||||||
|
title: "Divisi Baru",
|
||||||
|
body: "Anda memiliki divisi baru. Silahkan periksa detailnya.",
|
||||||
|
data: { id: data.id, category: "division", content: data.id }
|
||||||
|
})
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data divisi', table: 'division', data: data.id, user: userId })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data divisi', table: 'division', data: data.id, user: userId })
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import "moment/locale/id";
|
import "moment/locale/id";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendFCMNotificationMany } from "../../../../../xsendMany";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DATA PROJECT
|
// GET ALL DATA PROJECT
|
||||||
@@ -237,6 +238,11 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,10 +251,17 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
|
|
||||||
// mengirim notifikasi
|
// mengirim notifikasi
|
||||||
|
// dataFCM untuk push notifikasi mobile
|
||||||
// datanotif untuk realtime notifikasi
|
// datanotif untuk realtime notifikasi
|
||||||
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
// datapush untuk web push notifikasi ketika aplikasi tidak
|
||||||
|
const dataFCM = memberNotif.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||||
|
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||||
|
|
||||||
const dataNotif = memberNotif.map((v: any) => ({
|
const dataNotif = memberNotif.map((v: any) => ({
|
||||||
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUserTo: v.idUser,
|
idUserTo: v.idUser,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
category: 'project',
|
category: 'project',
|
||||||
@@ -258,7 +271,7 @@ export async function POST(request: Request) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
const dataPush = memberNotif.map((v: any) => ({
|
const dataPush = memberNotif.map((v: any) => ({
|
||||||
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUser: v.idUser,
|
idUser: v.idUser,
|
||||||
subscription: v.User.Subscribe?.subscription,
|
subscription: v.User.Subscribe?.subscription,
|
||||||
}))
|
}))
|
||||||
@@ -276,10 +289,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: perbekel?.id,
|
idUserTo: perbekel?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -311,10 +331,21 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const omitFCM = atasanGroup.map((v: any) => ({
|
||||||
|
..._.omit(v, ["id", "Subscribe", "TokenDeviceUser"]),
|
||||||
|
tokens: v.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
const omitData = atasanGroup.map((v: any) => ({
|
const omitData = atasanGroup.map((v: any) => ({
|
||||||
..._.omit(v, ["id", "Subscribe"]),
|
..._.omit(v, ["id", "Subscribe"]),
|
||||||
idUserTo: v.id,
|
idUserTo: v.id,
|
||||||
@@ -333,16 +364,24 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
dataNotif.push(...omitData)
|
dataNotif.push(...omitData)
|
||||||
dataPush.push(...omitPush)
|
dataPush.push(...omitPush)
|
||||||
|
tokenDup.push(...omitFCM.map((v: any) => v.tokens).flat())
|
||||||
}
|
}
|
||||||
|
|
||||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||||
|
|
||||||
// const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Kegiatan Baru', body: 'Terdapat kegiatan baru. Silahkan periksa detailnya.' } })
|
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Kegiatan Baru', body: 'Terdapat kegiatan baru. Silahkan periksa detailnya.' } })
|
||||||
const insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
|
await sendFCMNotificationMany({
|
||||||
|
token: tokenUnique,
|
||||||
|
title: "Kegiatan Baru",
|
||||||
|
body: "Anda memiliki kegiatan baru. Silahkan periksa detailnya.",
|
||||||
|
data: { id: data.id, category: "project", content: data.id }
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id, user: userMobile.id })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id, user: userMobile.id })
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies, funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUser, createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendFCMNotificationMany } from "../../../../../xsendMany";
|
||||||
|
|
||||||
|
|
||||||
// GET ALL DATA TUGAS DIVISI
|
// GET ALL DATA TUGAS DIVISI
|
||||||
@@ -222,6 +223,11 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,10 +235,17 @@ export async function POST(request: Request) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// mengirim notifikasi
|
// mengirim notifikasi
|
||||||
|
// dataFCM untuk push notifikasi mobile
|
||||||
// datanotif untuk realtime notifikasi
|
// datanotif untuk realtime notifikasi
|
||||||
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
||||||
|
const dataFCM = memberDivision.map((v: any) => ({
|
||||||
|
..._.omit(v, ["User", "Subscribe", "TokenDeviceUser"]),
|
||||||
|
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||||
|
}))
|
||||||
|
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||||
|
|
||||||
const dataNotif = memberDivision.map((v: any) => ({
|
const dataNotif = memberDivision.map((v: any) => ({
|
||||||
..._.omit(v, ["User", "Subscribe"]),
|
..._.omit(v, ["User", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUserTo: v.User.id,
|
idUserTo: v.User.id,
|
||||||
idUserFrom: String(userMobile.id),
|
idUserFrom: String(userMobile.id),
|
||||||
category: 'division/' + idDivision + '/task',
|
category: 'division/' + idDivision + '/task',
|
||||||
@@ -242,7 +255,7 @@ export async function POST(request: Request) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
const dataPush = memberDivision.map((v: any) => ({
|
const dataPush = memberDivision.map((v: any) => ({
|
||||||
..._.omit(v, ["User", "Subscribe"]),
|
..._.omit(v, ["User", "Subscribe", "TokenDeviceUser"]),
|
||||||
idUser: v.User.id,
|
idUser: v.User.id,
|
||||||
subscription: v.User.Subscribe?.subscription,
|
subscription: v.User.Subscribe?.subscription,
|
||||||
}))
|
}))
|
||||||
@@ -260,10 +273,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: perbekel?.id,
|
idUserTo: perbekel?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -292,10 +312,17 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
subscription: true
|
subscription: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
TokenDeviceUser: {
|
||||||
|
select: {
|
||||||
|
token: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tokenDup.push(ketuaGrup?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
|
|
||||||
dataNotif.push({
|
dataNotif.push({
|
||||||
idUserTo: ketuaGrup?.id,
|
idUserTo: ketuaGrup?.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
@@ -313,11 +340,18 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||||
|
|
||||||
// const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { body: 'Terdapat tugas baru. Silahkan periksa detailnya.', title: 'Tugas Baru' } })
|
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { body: 'Terdapat tugas baru. Silahkan periksa detailnya.', title: 'Tugas Baru' } })
|
||||||
const insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
|
await sendFCMNotificationMany({
|
||||||
|
token: tokenUnique,
|
||||||
|
title: "Tugas Baru",
|
||||||
|
body: "Anda memiliki tugas baru. Silahkan periksa detailnya.",
|
||||||
|
data: { id: data.id, category:'division/' + idDivision + '/task', content: data.id }
|
||||||
|
})
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat tugas divisi baru', table: 'divisionProject', data: data.id, user: userMobile.id })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat tugas divisi baru', table: 'divisionProject', data: data.id, user: userMobile.id })
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
return NextResponse.json({ success: true, version: "1.5.4", tahap: "beta", update: "-percobaan firebase admin fcm many device (tambah pengumuman)" }, { status: 200 });
|
return NextResponse.json({ success: true, version: "1.5.5", tahap: "beta", update: "-firebase notification many device" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(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 });
|
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
|||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
},
|
},
|
||||||
token,
|
tokens:token,
|
||||||
data,
|
data,
|
||||||
android: {
|
android: {
|
||||||
priority: "high",
|
priority: "high",
|
||||||
@@ -42,10 +42,7 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Kirim pesan
|
// Kirim pesan
|
||||||
const response = await getMessaging().sendEachForMulticast({
|
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||||
tokens: token,
|
|
||||||
...message,
|
|
||||||
} as any);
|
|
||||||
if (response.failureCount > 0) {
|
if (response.failureCount > 0) {
|
||||||
const failedTokens: any[] = [];
|
const failedTokens: any[] = [];
|
||||||
response.responses.forEach((resp, idx) => {
|
response.responses.forEach((resp, idx) => {
|
||||||
@@ -59,6 +56,5 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
|||||||
return { success: true, message: "Notifikasi berhasil dikirim", };
|
return { success: true, message: "Notifikasi berhasil dikirim", };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error mengirim notifikasi:", error);
|
console.error("Error mengirim notifikasi:", error);
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user