1
1
/* eslint no-underscore-dangle: ["error", { "allow": ["_id"] }] */
2
2
export default {
3
3
Query : {
4
- procedures : async ( parent , { type, offset, pageSize } , { ProcedureModel, ActivityModel } ) => {
4
+ procedures : async ( parent , { type, offset, pageSize } , { ProcedureModel } ) => {
5
5
let currentStates = [ ] ;
6
6
switch ( type ) {
7
7
case 'PREPARATION' :
@@ -58,12 +58,7 @@ export default {
58
58
return ProcedureModel . find ( { currentStatus : { $in : currentStates } , period } )
59
59
. sort ( sort )
60
60
. skip ( offset )
61
- . limit ( pageSize )
62
- . then ( results =>
63
- results . map ( async ( procedure ) => {
64
- const activityIndex = await ActivityModel . find ( { procedure } ) . count ( ) ;
65
- return { ...procedure . toObject ( ) , activityIndex } ;
66
- } ) ) ;
61
+ . limit ( pageSize ) ;
67
62
}
68
63
69
64
const activeVotings = await ProcedureModel . find ( {
@@ -83,28 +78,14 @@ export default {
83
78
. sort ( sort )
84
79
. skip ( offset - activeVotings . length > 0 ? offset - activeVotings . length : 0 )
85
80
. limit ( pageSize - activeVotings . length )
86
- . then ( finishedVotings => [ ...activeVotings , ...finishedVotings ] )
87
- . then ( results =>
88
- results . map ( async ( procedure ) => {
89
- const activityIndex = await ActivityModel . find ( { procedure } ) . count ( ) ;
90
- return { ...procedure . toObject ( ) , activityIndex } ;
91
- } ) ) ;
81
+ . then ( finishedVotings => [ ...activeVotings , ...finishedVotings ] ) ;
92
82
} ,
93
- procedure : async ( parent , { id } , { ProcedureModel, ActivityModel } ) =>
94
- ProcedureModel . findOne ( { procedureId : id } ) . then ( async ( procedure ) => {
95
- const activityIndex = await ActivityModel . find ( { procedure } ) . count ( ) ;
96
- return { ...procedure . toObject ( ) , activityIndex } ;
97
- } ) ,
98
- searchProcedures : ( parent , { term } , { ProcedureModel, ActivityModel } ) =>
83
+ procedure : async ( parent , { id } , { ProcedureModel } ) =>
84
+ ProcedureModel . findOne ( { procedureId : id } ) ,
85
+ searchProcedures : ( parent , { term } , { ProcedureModel } ) =>
99
86
ProcedureModel . find (
100
87
{ $text : { $search : term } , period : 19 } ,
101
88
{ score : { $meta : 'textScore' } } ,
102
- )
103
- . sort ( { score : { $meta : 'textScore' } } )
104
- . then ( results =>
105
- results . map ( async ( procedure ) => {
106
- const activityIndex = await ActivityModel . find ( { procedure } ) . count ( ) ;
107
- return { ...procedure . toObject ( ) , activityIndex } ;
108
- } ) ) ,
89
+ ) . sort ( { score : { $meta : 'textScore' } } ) ,
109
90
} ,
110
91
} ;
0 commit comments