fix: WebPush Notification

This commit is contained in:
Paolo Arena
2019-02-13 18:47:58 +01:00
parent df31a9ea9b
commit 0b4ac6391d
8 changed files with 115 additions and 88 deletions

View File

@@ -4,6 +4,8 @@ const mongoose = require('mongoose');
const Subscription = mongoose.model('subscribers');
const webpush = require('web-push');
const tools = require('../tools/general');
var { authenticate } = require('../middleware/authenticate');
const isValidSaveRequest = (req, res) => {
@@ -47,8 +49,12 @@ router.post('/', (req, res) => {
})
.then(myitem => {
if (myitem === null)
if (myitem === null) {
myitem = subscriptionModel;
tools.mylogshow('Subscription NOT EXISTED IN DB, so I use this created!', myitem)
}else
tools.mylogshow('Subscription already Existed!', myitem)
myitem.save((err, subscription) => {
if (err) {