- Created first Test with Mocha
This commit is contained in:
@@ -5,20 +5,23 @@ const Subscription = mongoose.model('subscribers');
|
||||
const webpush = require('web-push');
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const subscriptionModel = new Subscription(req.body.subs);
|
||||
subscriptionModel.save((err, subscription) => {
|
||||
if (err) {
|
||||
console.error(`Error occurred while saving subscription. Err: ${err}`);
|
||||
res.status(500).json({
|
||||
error: 'Technical error occurred'
|
||||
});
|
||||
} else {
|
||||
// Send 201 - resource created
|
||||
res.status(201).json({ data: 'Subscription saved.' });
|
||||
console.log('req.body.others', req.body.others);
|
||||
let subscriptionModel = new Subscription(req.body.subs);
|
||||
subscriptionModel.userId = req.body.others.userId
|
||||
|
||||
sendBackNotif(subscription, req.body.options)
|
||||
}
|
||||
});
|
||||
subscriptionModel.save((err, subscription) => {
|
||||
if (err) {
|
||||
console.error(`Error occurred while saving subscription. Err: ${err}`);
|
||||
res.status(500).json({
|
||||
error: 'Technical error occurred'
|
||||
});
|
||||
} else {
|
||||
// Send 201 - resource created
|
||||
res.status(201).json({ data: 'Subscription saved.' });
|
||||
|
||||
sendBackNotif(subscription, req.body.options)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function sendBackNotif(subscription, payload) {
|
||||
@@ -30,11 +33,10 @@ function sendBackNotif(subscription, payload) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.json({
|
||||
data: 'Invalid Request Bad'
|
||||
});
|
||||
res.json({
|
||||
data: 'Invalid Request Bad'
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user