Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit f98c356

Browse files
committed
fixed associatedCanDos hook
1 parent 2f42d33 commit f98c356

File tree

4 files changed

+378
-31
lines changed

4 files changed

+378
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"istanbul": "1.1.0-alpha.1",
111111
"mocha": "~5.2.0",
112112
"nodemon": "~1.17.4",
113+
"nyc": "^12.0.2",
113114
"wait-on": "~2.1.0"
114115
}
115116
}

server/services/contributions/hooks/get-associated-can-dos.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,26 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
2929
return contributionService.find({
3030
query: {
3131
type: 'cando',
32-
isEnabled: true
33-
}
34-
}, { _populate: 'skip' })
32+
isEnabled: true,
33+
categoryIds: {
34+
$in: categoryIds
35+
},
36+
$limit: limit,
37+
},
38+
_populate: 'skip'
39+
})
3540
.then(({data}) => {
36-
let associatedCanDos = [];
37-
while (associatedCanDos.length < limit && data.length) {
38-
let item = data.shift();
39-
let check = categoryIds.some(id => {
40-
return item.categoryIds.some(innerId => {
41-
return innerId.toString() == id.toString();
42-
});
43-
});
44-
if (check && item._id.toString() !== currentData._id.toString()) {
45-
associatedCanDos.push(item);
46-
}
47-
}
4841
if (isArray) {
49-
hook.result.data[0].associatedCanDos = associatedCanDos;
42+
hook.result.data[0].associatedCanDos = data;
5043
} else {
51-
hook.result.associatedCanDos = associatedCanDos;
44+
hook.result.associatedCanDos = data;
5245
}
5346
return resolve(hook);
5447
})
55-
.catch(() => {
48+
.catch(err => {
49+
// eslint-disable-next-line
50+
console.log(err);
51+
hook.app.error('issue while fetching associated candos');
5652
return resolve(hook);
5753
});
5854
});

test/services/contributions.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
} = require('../assets/contributions');
1313
const { categoryData } = require('../assets/categories');
1414

15-
describe('\'contributions\' service', () => {
15+
describe.only('\'contributions\' service', () => {
1616
let user;
1717
let params;
1818

0 commit comments

Comments
 (0)