Created
December 28, 2016 07:34
-
-
Save ailabs-software/e361d03815e4891c8d3065b8b443fc34 to your computer and use it in GitHub Desktop.
order.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var existingOrders = Orders.find(); | |
var openOrderIds = []; | |
var itemsOrdered = []; | |
existingOrders.forEach(function(order) { | |
if (order.isOpen && !order.isAcceptingMoreItems) { | |
openOrderIds.push(order); | |
var anyOpenOrder = false; | |
order.itemsOrdered.forEach(function(item) { | |
if (item.isOpen) { | |
anyOpenOrder = true; | |
for (var i = 0; i < orderedLineItemsToUpdate.length; i++) { | |
if (orderedLineItemsToUpdate[i].itemId == item.itemId) { | |
var lineItemProperties = { 'itemId': orderedLineItemsToUpdate[i].itemId, 'isOpen': false } | |
var theOrder = order; | |
var theItemId = lineItemProperties.itemId; | |
Meteor.call('updateOrderedItem', theOrder, theItemId, lineItemProperties, function(error, result) { | |
if (!error) Session.set('itemsCreatedCount', result) | |
console.log(error); | |
}); | |
} | |
} | |
} | |
if (!anyOpenOrder) { | |
Orders.update(order._id, { | |
$set: { 'isOpen': false } | |
}, function(error) { | |
if (error) throwError(error.reason + ' could not close order'); | |
}); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment