This repository was archived by the owner on Jun 27, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +378
-31
lines changed
server/services/contributions/hooks Expand file tree Collapse file tree 4 files changed +378
-31
lines changed Original file line number Diff line number Diff line change 110
110
"istanbul" : " 1.1.0-alpha.1" ,
111
111
"mocha" : " ~5.2.0" ,
112
112
"nodemon" : " ~1.17.4" ,
113
+ "nyc" : " ^12.0.2" ,
113
114
"wait-on" : " ~2.1.0"
114
115
}
115
116
}
Original file line number Diff line number Diff line change @@ -29,30 +29,26 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
29
29
return contributionService . find ( {
30
30
query : {
31
31
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
+ } )
35
40
. 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
- }
48
41
if ( isArray ) {
49
- hook . result . data [ 0 ] . associatedCanDos = associatedCanDos ;
42
+ hook . result . data [ 0 ] . associatedCanDos = data ;
50
43
} else {
51
- hook . result . associatedCanDos = associatedCanDos ;
44
+ hook . result . associatedCanDos = data ;
52
45
}
53
46
return resolve ( hook ) ;
54
47
} )
55
- . catch ( ( ) => {
48
+ . catch ( err => {
49
+ // eslint-disable-next-line
50
+ console . log ( err ) ;
51
+ hook . app . error ( 'issue while fetching associated candos' ) ;
56
52
return resolve ( hook ) ;
57
53
} ) ;
58
54
} ) ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const {
12
12
} = require ( '../assets/contributions' ) ;
13
13
const { categoryData } = require ( '../assets/categories' ) ;
14
14
15
- describe ( '\'contributions\' service' , ( ) => {
15
+ describe . only ( '\'contributions\' service' , ( ) => {
16
16
let user ;
17
17
let params ;
18
18
You can’t perform that action at this time.
0 commit comments