added topic messaging
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Xeovalyte 2023-01-22 15:42:45 +01:00
parent a18491a1a2
commit 9a5cf46400
3 changed files with 30 additions and 21 deletions

View File

@ -7,6 +7,12 @@
<label class="font-bold">Beschrijving</label> <label class="font-bold">Beschrijving</label>
<textarea v-model="form.description" required="true" class="input mb-5" /> <textarea v-model="form.description" required="true" class="input mb-5" />
<label class="font-bold">Groep</label>
<select v-model="form.topic" required="true" class="input mb-5">
<option value="all">Iedereen</option>
<option value="test">Test</option>
</select>
<div class="w-full flex flex-wrap justify-between"> <div class="w-full flex flex-wrap justify-between">
<input :disabled="disableButtons" type="submit" value="Stuur Bericht" class="btn w-full sm:w-40 mb-1"> <input :disabled="disableButtons" type="submit" value="Stuur Bericht" class="btn w-full sm:w-40 mb-1">
<button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Annuleer</button> <button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Annuleer</button>
@ -33,6 +39,7 @@ const disableButtons = ref(false)
const form = ref({ const form = ref({
title: '', title: '',
description: '', description: '',
topic: ''
}) })
const sendNews = async () => { const sendNews = async () => {
@ -44,7 +51,7 @@ const sendNews = async () => {
const { error } = await useFetch('/api/sendmessage', { const { error } = await useFetch('/api/sendmessage', {
method: 'post', method: 'post',
body: { title: form.value.title, body: form.value.description, token: idToken } body: { title: form.value.title, body: form.value.description, token: idToken, topic: form.value.topic }
}) })
if (error.value) { if (error.value) {

View File

@ -3,11 +3,13 @@ import { getAuth } from 'firebase-admin/auth'
import { getMessaging } from 'firebase-admin/messaging' import { getMessaging } from 'firebase-admin/messaging'
export default defineEventHandler(async event => { export default defineEventHandler(async event => {
const { token, body, title } = await readBody(event); const { token, body, title, topic } = await readBody(event);
if (!token) throw createError({ statusCode: 400, statusMessage: 'no-token'}) if (!token) throw createError({ statusCode: 400, statusMessage: 'no-token'})
if (!body) throw createError({ statusCode: 400, statusMessage: 'no-body'}) if (!body) throw createError({ statusCode: 400, statusMessage: 'no-body'})
if (!title) throw createError({ statusCode: 400, statusMessage: 'no-title'}) if (!title) throw createError({ statusCode: 400, statusMessage: 'no-title'})
if (!topic) throw createError({ statusCode: 400, statusMessage: 'no-topic'})
let decodedToken = null; let decodedToken = null;
@ -42,7 +44,7 @@ export default defineEventHandler(async event => {
icon: '/ios/256.png' icon: '/ios/256.png'
} }
}, },
topic: 'test', topic: topic,
apns: { apns: {
payload: { payload: {
aps: { aps: {