Last active
December 28, 2015 10:49
-
-
Save maxbeatty/7488652 to your computer and use it in GitHub Desktop.
This file contains 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
findAllWithLineItems: (id, searchCriteria, cb) -> | |
self = @ | |
Step( | |
-> | |
self.findAll searchCriteria, @ | |
return | |
(err, orders) -> | |
return cb err if err | |
isocketOrderUids = [] | |
scleraOrderUids = [] | |
_.each orders, (order) -> | |
if order.isocketId | |
isocketOrderUids.push order.isocketId | |
else | |
scleraOrderUids.push order.id | |
# if the order has an isocketId, that means all the current | |
# data is now in isocket and we bypass local db in favor of | |
# isocket data.. so here we do the split. | |
# get line items from isocket if there's an isocketId | |
# or from local db if there is no isocketId | |
if scleraOrderUids.length is 0 and isocketOrderUids.length is 0 | |
@() # next | |
else | |
if scleraOrderUids | |
lineItemRepo.findAll { | |
where: | |
id: scleraOrderUids | |
}, @parallel() | |
if isocketOrderUids | |
isocketOrderRepo.findOrders id, { | |
filters: [{ | |
name: 'uid' | |
values: orderUids | |
} ] | |
} , ['uid', 'status', 'lineItems'], @parallel() | |
return | |
(err, scleraLineItems, isocketLineItems) -> | |
# ... | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@()
would actually be something like@ null, [], []