Skip to content

Commit a921a92

Browse files
committed
fix function TeamService._getJobsByProjectIds()
1 parent 512df40 commit a921a92

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/services/JobService.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,23 @@ deleteJob.schema = Joi.object().keys({
261261
/**
262262
* List jobs
263263
* @params {Object} criteria the search criteria
264+
* @params {Object} options the extra options to control the function
264265
* @returns {Object} the search result, contain total/page/perPage and result array
265266
*/
266-
async function searchJobs (criteria) {
267+
async function searchJobs (criteria, options = { returnAll: false }) {
267268
const page = criteria.page > 0 ? criteria.page : 1
268-
const perPage = criteria.perPage > 0 ? criteria.perPage : 20
269+
let perPage
270+
if (options.returnAll) {
271+
// To simplify the logic we are use a very large number for perPage
272+
// because in practice there could hardly be so many records to be returned.(also consider we are using filters in the meantime)
273+
// the number is limited by `index.max_result_window`, its default value is 10000, see
274+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-max-result-window
275+
//
276+
// also see `ResourceBookingService.searchResourceBookings()`
277+
perPage = 10000
278+
} else {
279+
perPage = criteria.perPage > 0 ? criteria.perPage : 20
280+
}
269281
if (!criteria.sortBy) {
270282
criteria.sortBy = 'id'
271283
}
@@ -429,7 +441,8 @@ searchJobs.schema = Joi.object().keys({
429441
workload: Joi.workload(),
430442
status: Joi.jobStatus(),
431443
projectIds: Joi.array().items(Joi.number().integer()).single()
432-
}).required()
444+
}).required(),
445+
options: Joi.object()
433446
}).required()
434447

435448
module.exports = {

src/services/TeamService.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function _getAssignedResourceBookingsByProjectIds (projectIds) {
2828
* @returns the request result
2929
*/
3030
async function _getJobsByProjectIds (projectIds) {
31-
const { result } = await JobService.searchJobs({ projectIds })
31+
const { result } = await JobService.searchJobs({ projectIds }, { returnAll: true })
3232
return result
3333
}
3434

@@ -176,6 +176,10 @@ async function getTeamDetail (currentUser, projects, isSearch = true) {
176176
// Count total positions
177177
res.totalPositions = 0
178178
for (const item of jobsTmp) {
179+
// only sum numPositions of jobs whose status is NOT cancelled or closed
180+
if (['cancelled', 'closed'].includes(item.status)) {
181+
continue
182+
}
179183
res.totalPositions += item.numPositions
180184
}
181185
} else {

0 commit comments

Comments
 (0)