-
Notifications
You must be signed in to change notification settings - Fork 0
/
deliveryManager.js
44 lines (32 loc) · 1.35 KB
/
deliveryManager.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 orderManager = require('./orderManager');
const customerServiceManager = require('./customerServiceManager');
const AWS = require('aws-sdk');
const sqs = new AWS.SQS({ region: process.env.region });
const DELIVERY_COMPANY_QUEUE = process.env.deliveryCompanyQueue;
module.exports.deliveryOrder = ordersFulfilled => {
var orderFulfilledPromises = [];
for (let order of ordersFulfilled) {
const temp = orderManager.updateOrderForDelivery(order.orderId).then(updatedOrder => {
orderManager.saveOrder(updatedOrder).then(() => {
notifyDeliveryCompany(updatedOrder);
});
});
orderFulfilledPromises.push(temp);
};
return Promise.all(orderFulfilledPromises);
}
module.exports.orderDelivered = (orderId, deliveryCompanyId, orderReview) => {
return orderManager.updateOrderAfterDelivery(orderId, deliveryCompanyId, orderReview).then(updatedOrder => {
return orderManager.saveOrder(updatedOrder).then(() => {
return customerServiceManager.notifyCustomerServiceForReview(orderId, orderReview);
});
});
}
function notifyDeliveryCompany(order) {
const params = {
MessageBody: JSON.stringify(order),
QueueUrl: DELIVERY_COMPANY_QUEUE
};
return sqs.sendMessage(params).promise();
}