feat: add employee push test button
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { FastifyInstance } from "fastify"
|
||||
import { and, eq, isNull } from "drizzle-orm"
|
||||
import { authUsers, notificationMobilePushDevices } from "../../db/schema"
|
||||
import { authProfiles, authUsers, notificationMobilePushDevices } from "../../db/schema"
|
||||
import { NotificationService, UserDirectory } from "../modules/notification.service"
|
||||
import { pushServerClient } from "../modules/push-server.client"
|
||||
|
||||
@@ -174,6 +174,60 @@ export default async function notificationsRoutes(server: FastifyInstance) {
|
||||
})
|
||||
})
|
||||
|
||||
server.post("/notifications/test-push/profile/:profileId", async (req, reply) => {
|
||||
const tenantId = requireTenant(req.user.tenant_id)
|
||||
const { profileId } = req.params as { profileId: string }
|
||||
const [profile] = await server.db
|
||||
.select({
|
||||
userId: authProfiles.user_id,
|
||||
})
|
||||
.from(authProfiles)
|
||||
.where(and(
|
||||
eq(authProfiles.id, profileId),
|
||||
eq(authProfiles.tenant_id, tenantId)
|
||||
))
|
||||
.limit(1)
|
||||
|
||||
if (!profile) {
|
||||
return reply.code(404).send({ error: "Mitarbeiter nicht gefunden" })
|
||||
}
|
||||
|
||||
if (!profile.userId) {
|
||||
return reply.code(409).send({
|
||||
error: "Der Mitarbeiter ist noch nicht mit einem Benutzerkonto verknüpft",
|
||||
})
|
||||
}
|
||||
|
||||
const result = await svc.trigger({
|
||||
tenantId,
|
||||
userId: profile.userId,
|
||||
eventType: "system.test_push",
|
||||
title: "FEDEO Push ist aktiv",
|
||||
message: "Diese Testbenachrichtigung wurde einmalig über das Mitarbeiterprofil ausgelöst.",
|
||||
payload: {
|
||||
link: "/",
|
||||
icon: "/favicon.ico",
|
||||
},
|
||||
channels: ["push"],
|
||||
})
|
||||
|
||||
if (result.created === 0) {
|
||||
return reply.code(409).send({
|
||||
error: "Pushnachrichten sind für diesen Mitarbeiter deaktiviert",
|
||||
result,
|
||||
})
|
||||
}
|
||||
|
||||
if (!result.success || result.delivered === 0) {
|
||||
return reply.code(424).send({
|
||||
error: "Die Pushnachricht konnte an kein aktives Gerät zugestellt werden",
|
||||
result,
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
server.post("/notifications/trigger", async (req, reply) => {
|
||||
try {
|
||||
const body = req.body as any
|
||||
|
||||
Reference in New Issue
Block a user