Skip to content

fix and update the calculation of totalPositions #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/services/JobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,23 @@ deleteJob.schema = Joi.object().keys({
/**
* List jobs
* @params {Object} criteria the search criteria
* @params {Object} options the extra options to control the function
* @returns {Object} the search result, contain total/page/perPage and result array
*/
async function searchJobs (criteria) {
async function searchJobs (criteria, options = { returnAll: false }) {
const page = criteria.page > 0 ? criteria.page : 1
const perPage = criteria.perPage > 0 ? criteria.perPage : 20
let perPage
if (options.returnAll) {
// To simplify the logic we are use a very large number for perPage
// because in practice there could hardly be so many records to be returned.(also consider we are using filters in the meantime)
// the number is limited by `index.max_result_window`, its default value is 10000, see
// https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-max-result-window
//
// also see `ResourceBookingService.searchResourceBookings()`
perPage = 10000
} else {
perPage = criteria.perPage > 0 ? criteria.perPage : 20
}
if (!criteria.sortBy) {
criteria.sortBy = 'id'
}
Expand Down Expand Up @@ -429,7 +441,8 @@ searchJobs.schema = Joi.object().keys({
workload: Joi.workload(),
status: Joi.jobStatus(),
projectIds: Joi.array().items(Joi.number().integer()).single()
}).required()
}).required(),
options: Joi.object()
}).required()

module.exports = {
Expand Down
6 changes: 5 additions & 1 deletion src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function _getAssignedResourceBookingsByProjectIds (projectIds) {
* @returns the request result
*/
async function _getJobsByProjectIds (projectIds) {
const { result } = await JobService.searchJobs({ projectIds })
const { result } = await JobService.searchJobs({ projectIds }, { returnAll: true })
return result
}

Expand Down Expand Up @@ -176,6 +176,10 @@ async function getTeamDetail (currentUser, projects, isSearch = true) {
// Count total positions
res.totalPositions = 0
for (const item of jobsTmp) {
// only sum numPositions of jobs whose status is NOT cancelled or closed
if (['cancelled', 'closed'].includes(item.status)) {
continue
}
res.totalPositions += item.numPositions
}
} else {
Expand Down