pushing things I forgot

This commit is contained in:
Kasper Rynning-Tønnesen
2020-02-21 09:54:16 +01:00
parent 8585b85d79
commit ac1e73ee09
4 changed files with 30 additions and 3 deletions

View File

@@ -64,7 +64,11 @@ router.route("/send-notification").post(async (req, res) => {
res.send(false);
return;
}
const message = req.body.message;
const message = JSON.stringify({
message: req.body.message,
title: "Vinlotteri!"
});
let subs = await Subscription.find();
for (let i = 0; i < subs.length; i++) {
let subscription = subs[i]; //get subscription from your databse here.
@@ -80,10 +84,14 @@ schedule.scheduleJob(
let subs = await Subscription.find();
for (let i = 0; i < subs.length; i++) {
let subscription = subs[i]; //get subscription from your databse here.
const message = "Husk vinlotteriet, det begynner om 10 minutter!";
const message = JSON.stringify({
message: "Husk vinlotteriet, det begynner om 10 minutter!",
title: "Vinlotteri!"
});
sendNotification(subscription, message);
}
}
);
module.exports = router;
module.exports.sendNotification = sendNotification;

View File

@@ -6,6 +6,9 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", {
useNewUrlParser: true
});
const sub = require(path.join(__dirname + "/../api/subscriptions"));
const Subscription = require(path.join(__dirname + "/../schemas/Subscription"));
const Purchase = require(path.join(__dirname + "/../schemas/Purchase"));
const Wine = require(path.join(__dirname + "/../schemas/Wine"));
const PreLotteryWine = require(path.join(
@@ -35,6 +38,16 @@ router.route("/log/wines").post(async (req, res) => {
await newWonWine.save();
}
let subs = await Subscription.find();
for (let i = 0; i < subs.length; i++) {
let subscription = subs[i]; //get subscription from your databse here.
const message = JSON.stringify({
message: "Dagens vin er lagt til, se den på lottis.vin/dagens!",
title: "Ny vin!"
});
sub.sendNotification(subscription, message);
}
res.send(true);
});