File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -260,11 +260,23 @@ deleteJob.schema = Joi.object().keys({
260
260
/**
261
261
* List jobs
262
262
* @params {Object} criteria the search criteria
263
+ * @params {Object} options the extra options to control the function
263
264
* @returns {Object } the search result, contain total/page/perPage and result array
264
265
*/
265
- async function searchJobs ( criteria ) {
266
+ async function searchJobs ( criteria , options = { returnAll : false } ) {
266
267
const page = criteria . page > 0 ? criteria . page : 1
267
- const perPage = criteria . perPage > 0 ? criteria . perPage : 20
268
+ let perPage
269
+ if ( options . returnAll ) {
270
+ // To simplify the logic we are use a very large number for perPage
271
+ // because in practice there could hardly be so many records to be returned.(also consider we are using filters in the meantime)
272
+ // the number is limited by `index.max_result_window`, its default value is 10000, see
273
+ // https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-max-result-window
274
+ //
275
+ // also see `ResourceBookingService.searchResourceBookings()`
276
+ perPage = 10000
277
+ } else {
278
+ perPage = criteria . perPage > 0 ? criteria . perPage : 20
279
+ }
268
280
if ( ! criteria . sortBy ) {
269
281
criteria . sortBy = 'id'
270
282
}
@@ -428,7 +440,8 @@ searchJobs.schema = Joi.object().keys({
428
440
workload : Joi . workload ( ) ,
429
441
status : Joi . jobStatus ( ) ,
430
442
projectIds : Joi . array ( ) . items ( Joi . number ( ) . integer ( ) ) . single ( )
431
- } ) . required ( )
443
+ } ) . required ( ) ,
444
+ options : Joi . object ( )
432
445
} ) . required ( )
433
446
434
447
module . exports = {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ async function _getAssignedResourceBookingsByProjectIds (projectIds) {
28
28
* @returns the request result
29
29
*/
30
30
async function _getJobsByProjectIds ( projectIds ) {
31
- const { result } = await JobService . searchJobs ( { projectIds } )
31
+ const { result } = await JobService . searchJobs ( { projectIds } , { returnAll : true } )
32
32
return result
33
33
}
34
34
@@ -171,6 +171,10 @@ async function getTeamDetail (projects, isSearch = true) {
171
171
// Count total positions
172
172
res . totalPositions = 0
173
173
for ( const item of jobsTmp ) {
174
+ // only sum numPositions of jobs whose status is NOT cancelled or closed
175
+ if ( [ 'cancelled' , 'closed' ] . includes ( item . status ) ) {
176
+ continue
177
+ }
174
178
res . totalPositions += item . numPositions
175
179
}
176
180
} else {
You can’t perform that action at this time.
0 commit comments