Skip to content

Commit

Permalink
Whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
satyavh committed Oct 4, 2017
1 parent 53ca6fe commit b90d7fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
26 changes: 15 additions & 11 deletions src/services/campaigns/campaigns.hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@ module.exports = {
return new Promise((resolve, reject) => {
let promises = []

hook.result.data.map((campaign, i) => {
promises.push(hook.app.service('milestones').find({ query: {
campaignId: campaign._id,
$limit: 0
}}).then(count => {
campaign.milestonesCount = count.total
return campaign
}))
if(hook.result.data) {
hook.result.data.map((campaign, i) => {
promises.push(hook.app.service('milestones').find({ query: {
campaignId: campaign._id,
$limit: 0
}}).then(count => {
campaign.milestonesCount = count.total
return campaign
}))

})
})

Promise.all(promises).then(() => {
Promise.all(promises).then(() => {
resolve(hook)
})
} else {
resolve(hook)
})
}
})
}

Expand Down
26 changes: 15 additions & 11 deletions src/services/dacs/dacs.hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,24 @@ module.exports = {
return new Promise((resolve, reject) => {
let promises = []

hook.result.data.map((dac, i) => {
promises.push(hook.app.service('campaigns').find({ query: {
dacs: dac._id,
$limit: 0
}}).then(count => {
dac.campaignsCount = count.total
return dac
}))
if(hook.result.data) {
hook.result.data.map((dac, i) => {
promises.push(hook.app.service('campaigns').find({ query: {
dacs: dac._id,
$limit: 0
}}).then(count => {
dac.campaignsCount = count.total
return dac
}))

})
})

Promise.all(promises).then(() => {
Promise.all(promises).then(() => {
resolve(hook)
})
} else {
resolve(hook)
})
}
})
}],
get: [],
Expand Down

0 comments on commit b90d7fd

Please sign in to comment.