forked from debrajpaul/serverless-cake-ordering-system-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cakeProducerManager.js
44 lines (38 loc) · 1.01 KB
/
cakeProducerManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
const AWS = require("aws-sdk");
const ses = new AWS.SES({
region: process.env.region
});
const CAKE_PRODUCER_EMAIL = process.env.cakeProducerEmail;
const ORDERING_SYSTEM_EMAIL = process.env.orderingSystemEmail;
module.exports.handlePlacedOrders = ordersPlaced => {
let ordersPlacedPromises = [];
for (let order of ordersPlaced) {
ordersPlacedPromises.push(notifyCakeProducerByEmail(order));
}
return Promise.all(ordersPlacedPromises);
};
function notifyCakeProducerByEmail(order) {
const params = {
Destination: {
ToAddresses: [CAKE_PRODUCER_EMAIL]
},
Message: {
Body: {
Text: {
Data: JSON.stringify(order)
}
},
Subject: {
Data: "new cake order"
}
},
Source: ORDERING_SYSTEM_EMAIL
};
return ses
.sendEmail(params)
.promise()
.then(data => {
return data;
});
}