Sendnotification moved to the lambda / has bugs

This commit is contained in:
Senad Uka
2019-03-08 06:24:10 +01:00
parent 3f8e6438b2
commit 055ca54002
2 changed files with 35 additions and 3 deletions

View File

@@ -1,10 +1,38 @@
'use strict';
const path = require("path");
const bodyParser = require("body-parser");
const MarketAlert = require("./lib/MarketAlert");
const sendNotification = require("./lib/sendnotification");
const scrapTheItems = require("./lib/scraptheitems");
const sequelize = require("./lib/db.js");
const Twocheckout = require("2checkout-node");
module.exports.sendnotification = async (event, context) => {
let marketAlerts = await MarketAlert.findAll();
let lastDateUpdate = await Promise.all(
marketAlerts
.map(marketAlert => {
const { id, email, olx_url, last_date } = marketAlert.dataValues;
return { id, email, olx_url, last_date };
})
.map(sendNotification)
);
lastDateUpdate = lastDateUpdate.filter(Boolean(dateUpdate));
lastDateUpdate.length &&
lastDateUpdate.forEach(dateUpdate =>
MarketAlert.update(
{ last_date: dateUpdate.date },
{ where: { id: dateUpdate.id } }
)
);
return {
statusCode: 200,
body: JSON.stringify({
message: 'Send notification!',
message: 'Notifications sent',
input: event,
}),
};

View File

@@ -55,8 +55,12 @@ provider:
# - exclude-me-dir/**
functions:
hello:
handler: handler.hello
sendnotification:
handler: handler.sendnotification
events:
- http:
path: notifications/send
method: post
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events