Sendnotification moved to the lambda / has bugs
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user