-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelivery-manager.js
34 lines (30 loc) · 1.09 KB
/
delivery-manager.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
"use strict";
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 orderFulfilled) {
const temp = orderManager.update0rderForDelivery(order.orderId).then(updatedOrder => {
orderManager.saveOrder(updatedOrder).then ( () => {
notifyDeliverytompany(updatedOrder);
});
});
orderFulfilledPromises.push(temp);
};
return Promise.all(orderFulfilledPromises) ;
}
module.exports.orderDelivered = (orderId, deliveryCompanyId, orderReview) => {
return orderManager. update0rderAfterDelivery (orderId, deliveryCompanyId). then( updatedOrder => {
return customerServiceManager.notifyCustomerServiceForeview(orderId,orderReview);
});
}
function notifyDeliveryCompany(order) {
const params = {
MessageBody: JSON.stringify(order),
QueueUrl: DELIVERY_COMPANY_QUEUE
}
return sqs.sendMessage(params).promise();
}