-
Notifications
You must be signed in to change notification settings - Fork 0
/
deliveryManager.js
37 lines (30 loc) · 1.12 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
'use strict'
const AWS = require('aws-sdk');
const sqs = new AWS.SQS({
region: process.env.region
});
const orderManager = require('./orderManager');
const customerServiceManager = require('./customerServiceManager');
const DELIVERY_SERVICE_QUEUE = process.env.deliveryServiceQueue;
module.exports.handleOrderDelivery = ordersFulfilled => {
let ordersFulfilledPromises = [];
for (const order of ordersFulfilled) {
ordersFulfilledPromises.push(
orderManager.updateOrderForDelivery(order.orderId).then(updatedOrder => {
return notifyDeliveryCompany(updatedOrder);
})
);
}
return Promise.all(ordersFulfilledPromises);
}
const notifyDeliveryCompany = updatedOrder => {
return sqs.sendMessage({
MessageBody: JSON.stringify(updatedOrder),
QueueUrl: DELIVERY_SERVICE_QUEUE
}).promise();
}
module.exports.completeOrder = (orderId, deliveryCompanyId, orderReview) => {
return orderManager.updateOrderDeliveryData(orderId, deliveryCompanyId).then(() => {
return customerServiceManager.notifyCustomerReview(orderId, orderReview);
});
}