Skip to content

Instantly share code, notes, and snippets.

@maxbeatty
Last active December 28, 2015 10:49
Show Gist options
  • Save maxbeatty/7488652 to your computer and use it in GitHub Desktop.
Save maxbeatty/7488652 to your computer and use it in GitHub Desktop.
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) ->
# ...
)
@maxbeatty
Copy link
Author

@() would actually be something like @ null, [], []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment