-
Notifications
You must be signed in to change notification settings - Fork 1
/
deliveryManager.js
48 lines (41 loc) · 1.43 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
45
46
47
48
"use strict";
const AWS = require("aws-sdk");
const orderManager = require("./orderManager");
const customerServiceManager = require("./customerServiceManager");
const sqs = new AWS.SQS({
region: process.env.region
});
const DELIVERY_COMPANY_QUEUE = process.env.deliveryCompanyQueue;
module.exports.deliveryOrders = orderFulfilled => {
let orderFulfilledPromises = [];
for (let order of orderFulfilled) {
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)
.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();
}