Sendnotification moved to the lambda / has bugs
This commit is contained in:
@@ -1,10 +1,38 @@
|
|||||||
'use strict';
|
'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) => {
|
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 {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
message: 'Send notification!',
|
message: 'Notifications sent',
|
||||||
input: event,
|
input: event,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,8 +55,12 @@ provider:
|
|||||||
# - exclude-me-dir/**
|
# - exclude-me-dir/**
|
||||||
|
|
||||||
functions:
|
functions:
|
||||||
hello:
|
sendnotification:
|
||||||
handler: handler.hello
|
handler: handler.sendnotification
|
||||||
|
events:
|
||||||
|
- http:
|
||||||
|
path: notifications/send
|
||||||
|
method: post
|
||||||
|
|
||||||
# The following are a few example events you can configure
|
# The following are a few example events you can configure
|
||||||
# NOTE: Please make sure to change your handler code to work with those events
|
# NOTE: Please make sure to change your handler code to work with those events
|
||||||
|
|||||||
Reference in New Issue
Block a user