upd: web push
Deskripsi: - masang web push pada diskusi divisi - masang web push pada kegiatan - masang web push pada tugas divisi - update package bun No Issues
This commit is contained in:
7204
package-lock.json
generated
7204
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { funSendWebPush, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
@@ -158,6 +158,9 @@ export async function POST(request: Request) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// mengirim notifikasi
|
||||||
|
// datanotif untuk realtime notifikasi
|
||||||
|
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
||||||
const dataNotif = sent.member.map((v: any) => ({
|
const dataNotif = sent.member.map((v: any) => ({
|
||||||
..._.omit(v, ["idUser", "name", "img"]),
|
..._.omit(v, ["idUser", "name", "img"]),
|
||||||
idUserTo: v.idUser,
|
idUserTo: v.idUser,
|
||||||
@@ -168,12 +171,45 @@ export async function POST(request: Request) {
|
|||||||
desc: 'Terdapat divisi baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat divisi baru. Silahkan periksa detailnya.'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const selectUser = await prisma.divisionMember.findMany({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: data.id
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
idUser: true,
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataPush = selectUser.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
||||||
|
idUser: v.idUser,
|
||||||
|
subscription: v.User.Subscribe?.subscription,
|
||||||
|
}))
|
||||||
|
|
||||||
if (userRoleLogin != "supadmin") {
|
if (userRoleLogin != "supadmin") {
|
||||||
const perbekel = await prisma.user.findFirst({
|
const perbekel = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
idUserRole: "supadmin",
|
idUserRole: "supadmin",
|
||||||
idVillage: user.idVillage
|
idVillage: user.idVillage
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -185,6 +221,12 @@ export async function POST(request: Request) {
|
|||||||
title: 'Divisi Baru',
|
title: 'Divisi Baru',
|
||||||
desc: 'Terdapat divisi baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat divisi baru. Silahkan periksa detailnya.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dataPush.push({
|
||||||
|
idUser: perbekel?.id,
|
||||||
|
subscription: perbekel?.Subscribe?.subscription
|
||||||
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const atasanGroup = await prisma.user.findMany({
|
const atasanGroup = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -198,12 +240,17 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const omitData = atasanGroup.map((v: any) => ({
|
const omitData = atasanGroup.map((v: any) => ({
|
||||||
..._.omit(v, ["id"]),
|
..._.omit(v, ["id", "Subscribe"]),
|
||||||
idUserTo: v.id,
|
idUserTo: v.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
category: 'division',
|
category: 'division',
|
||||||
@@ -212,10 +259,21 @@ export async function POST(request: Request) {
|
|||||||
desc: 'Terdapat divisi baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat divisi baru. Silahkan periksa detailnya.'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const omitPush = atasanGroup.map((v: any) => ({
|
||||||
|
..._.omit(v, ["id", "Subscribe"]),
|
||||||
|
idUser: v.id,
|
||||||
|
subscription: v.Subscribe?.subscription,
|
||||||
|
}))
|
||||||
|
|
||||||
dataNotif.push(...omitData)
|
dataNotif.push(...omitData)
|
||||||
|
dataPush.push(...omitPush)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
@@ -203,12 +203,25 @@ export async function POST(request: Request) {
|
|||||||
idProject: data.id
|
idProject: data.id
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
idUser: true
|
idUser: true,
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// mengirim notifikasi
|
||||||
|
// datanotif untuk realtime notifikasi
|
||||||
|
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
||||||
const dataNotif = memberNotif.map((v: any) => ({
|
const dataNotif = memberNotif.map((v: any) => ({
|
||||||
..._.omit(v, ["idUser"]),
|
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
||||||
idUserTo: v.idUser,
|
idUserTo: v.idUser,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
category: 'project',
|
category: 'project',
|
||||||
@@ -217,12 +230,26 @@ export async function POST(request: Request) {
|
|||||||
desc: 'Terdapat kegiatan baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat kegiatan baru. Silahkan periksa detailnya.'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const dataPush = memberNotif.map((v: any) => ({
|
||||||
|
..._.omit(v, ["idUser", "User", "Subscribe"]),
|
||||||
|
idUser: v.idUser,
|
||||||
|
subscription: v.User.Subscribe?.subscription,
|
||||||
|
}))
|
||||||
|
|
||||||
if (userRoleLogin != "supadmin") {
|
if (userRoleLogin != "supadmin") {
|
||||||
const perbekel = await prisma.user.findFirst({
|
const perbekel = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
idUserRole: "supadmin",
|
idUserRole: "supadmin",
|
||||||
idVillage: user.idVillage
|
idVillage: user.idVillage
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -234,6 +261,11 @@ export async function POST(request: Request) {
|
|||||||
title: 'Kegiatan Baru',
|
title: 'Kegiatan Baru',
|
||||||
desc: 'Terdapat kegiatan baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat kegiatan baru. Silahkan periksa detailnya.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dataPush.push({
|
||||||
|
idUser: perbekel?.id,
|
||||||
|
subscription: perbekel?.Subscribe?.subscription
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
const atasanGroup = await prisma.user.findMany({
|
const atasanGroup = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -247,12 +279,17 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const omitData = atasanGroup.map((v: any) => ({
|
const omitData = atasanGroup.map((v: any) => ({
|
||||||
..._.omit(v, ["id"]),
|
..._.omit(v, ["id", "Subscribe"]),
|
||||||
idUserTo: v.id,
|
idUserTo: v.id,
|
||||||
idUserFrom: userId,
|
idUserFrom: userId,
|
||||||
category: 'project',
|
category: 'project',
|
||||||
@@ -261,10 +298,20 @@ export async function POST(request: Request) {
|
|||||||
desc: 'Terdapat kegiatan baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat kegiatan baru. Silahkan periksa detailnya.'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const omitPush = atasanGroup.map((v: any) => ({
|
||||||
|
..._.omit(v, ["id", "Subscribe"]),
|
||||||
|
idUser: v.id,
|
||||||
|
subscription: v.Subscribe?.subscription,
|
||||||
|
}))
|
||||||
|
|
||||||
dataNotif.push(...omitData)
|
dataNotif.push(...omitData)
|
||||||
|
dataPush.push(...omitPush)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import { createLogUser } from "@/module/user";
|
import { createLogUser } from "@/module/user";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
@@ -215,15 +215,22 @@ export async function POST(request: Request) {
|
|||||||
select: {
|
select: {
|
||||||
User: {
|
User: {
|
||||||
select: {
|
select: {
|
||||||
id: true
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// mengirim notifikasi
|
||||||
|
// datanotif untuk realtime notifikasi
|
||||||
|
// datapush untuk web push notifikasi ketika aplikasi tidak aktif
|
||||||
const dataNotif = memberDivision.map((v: any) => ({
|
const dataNotif = memberDivision.map((v: any) => ({
|
||||||
..._.omit(v, ["User"]),
|
..._.omit(v, ["User", "Subscribe"]),
|
||||||
idUserTo: v.User.id,
|
idUserTo: v.User.id,
|
||||||
idUserFrom: String(user.id),
|
idUserFrom: String(user.id),
|
||||||
category: 'division/' + idDivision + '/task',
|
category: 'division/' + idDivision + '/task',
|
||||||
@@ -232,12 +239,26 @@ export async function POST(request: Request) {
|
|||||||
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const dataPush = memberDivision.map((v: any) => ({
|
||||||
|
..._.omit(v, ["User", "Subscribe"]),
|
||||||
|
idUser: v.User.id,
|
||||||
|
subscription: v.User.Subscribe?.subscription,
|
||||||
|
}))
|
||||||
|
|
||||||
if (userRoleLogin != "supadmin") {
|
if (userRoleLogin != "supadmin") {
|
||||||
const perbekel = await prisma.user.findFirst({
|
const perbekel = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
idUserRole: "supadmin",
|
idUserRole: "supadmin",
|
||||||
idVillage: user.idVillage
|
idVillage: user.idVillage
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -249,8 +270,48 @@ export async function POST(request: Request) {
|
|||||||
title: 'Tugas Baru',
|
title: 'Tugas Baru',
|
||||||
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
dataPush.push({
|
||||||
|
idUser: perbekel?.id,
|
||||||
|
subscription: perbekel?.Subscribe?.subscription
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userRoleLogin != "cosupadmin") {
|
||||||
|
const ketuaGrup = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idUserRole: "cosupadmin",
|
||||||
|
idGroup: user.idGroup
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
Subscribe: {
|
||||||
|
select: {
|
||||||
|
subscription: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
dataNotif.push({
|
||||||
|
idUserTo: ketuaGrup?.id,
|
||||||
|
idUserFrom: userId,
|
||||||
|
category: 'division/' + idDivision + '/task',
|
||||||
|
idContent: data.id,
|
||||||
|
title: 'Tugas Baru',
|
||||||
|
desc: 'Terdapat tugas baru. Silahkan periksa detailnya.'
|
||||||
|
})
|
||||||
|
|
||||||
|
dataPush.push({
|
||||||
|
idUser: ketuaGrup?.id,
|
||||||
|
subscription: ketuaGrup?.Subscribe?.subscription
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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 insertNotif = await prisma.notifications.createMany({
|
const insertNotif = await prisma.notifications.createMany({
|
||||||
data: dataNotif
|
data: dataNotif
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
|
'use server'
|
||||||
import { WibuServerPush } from "wibu-pkg";
|
import { WibuServerPush } from "wibu-pkg";
|
||||||
|
|
||||||
|
WibuServerPush.init({
|
||||||
|
NEXT_PUBLIC_VAPID_PUBLIC_KEY: process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY!,
|
||||||
|
VAPID_PRIVATE_KEY: process.env.VAPID_PRIVATE_KEY!
|
||||||
|
})
|
||||||
|
|
||||||
export async function funSendWebPush({ sub, message }: { sub: { idUser: string, subscription: string }[], message: { body: string, title: string } }) {
|
export async function funSendWebPush({ sub, message }: { sub: { idUser: string, subscription: string }[], message: { body: string, title: string } }) {
|
||||||
try {
|
try {
|
||||||
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
||||||
|
|||||||
Reference in New Issue
Block a user