Skip to content

Roles finalfix #376

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 2 commits into from
Jun 23, 2021
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
7 changes: 7 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5249,6 +5249,9 @@ components:
jobDescription:
type: string
description: "The description of the job."
jobTitle:
type: string
description: "An optional job title."
- type: object
required:
- skills
Expand Down Expand Up @@ -5281,6 +5284,10 @@ components:
format: float
description: "Rate at which searched skills match the given role"
example: 0.75
jobTitle:
type: string
description: "Optional job title."
example: "Lead Application Developer"
SubmitTeamRequestBody:
properties:
teamName:
Expand Down
18 changes: 18 additions & 0 deletions migrations/2021-06-22-role-search-request-add-job-title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const config = require('config')

/**
* Add jobTitle field to the RoleSearchRequest model.
*/

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn({ tableName: 'role_search_requests', schema: config.DB_SCHEMA_NAME }, 'job_title',
{
type: Sequelize.STRING(100),
allowNull: true
})
},
down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn({ tableName: 'role_search_requests', schema: config.DB_SCHEMA_NAME}, 'job_title')
}
}
5 changes: 5 additions & 0 deletions src/models/RoleSearchRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ module.exports = (sequelize) => {
type: Sequelize.UUID
})
},
jobTitle: {
field: 'job_title',
type: Sequelize.STRING(100),
allowNull: true
},
createdBy: {
field: 'created_by',
type: Sequelize.UUID,
Expand Down
34 changes: 25 additions & 9 deletions src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const errors = require('../common/errors')
const JobService = require('./JobService')
const ResourceBookingService = require('./ResourceBookingService')
const HttpStatus = require('http-status-codes')
const { Op } = require('sequelize')
const { Op, where, fn, col } = require('sequelize')
const models = require('../models')
const stopWords = require('../../data/stopWords.json')
const { getAuditM2Muser } = require('../common/helper')
Expand Down Expand Up @@ -776,11 +776,12 @@ async function roleSearchRequest (currentUser, data) {
}
data.roleId = role.id
// create roleSearchRequest entity with found roleId
const { id: roleSearchRequestId } = await createRoleSearchRequest(currentUser, data)
const { id: roleSearchRequestId, jobTitle } = await createRoleSearchRequest(currentUser, data)
const entity = jobTitle ? { jobTitle, roleSearchRequestId } : { roleSearchRequestId };
// clean Role
role = await _cleanRoleDTO(currentUser, role)
// return Role
return _.assign(role, { roleSearchRequestId })
return _.assign(role, entity)
}

roleSearchRequest.schema = Joi.object()
Expand All @@ -789,8 +790,10 @@ roleSearchRequest.schema = Joi.object()
data: Joi.object().keys({
roleId: Joi.string().uuid(),
jobDescription: Joi.string().max(255),
skills: Joi.array().items(Joi.string().uuid().required())
}).required().min(1)
skills: Joi.array().items(Joi.string().uuid().required()),
jobTitle: Joi.string().max(100),
previousRoleSearchRequestId: Joi.string().uuid()
}).required().or('roleId', 'jobDescription', 'skills')
}).required()

/**
Expand All @@ -799,17 +802,30 @@ roleSearchRequest.schema = Joi.object()
* @returns {Role} the best matching Role
*/
async function getRoleBySkills (skills) {
// Case-insensitive search for roles matching any of the given skills
const lowerCaseSkills = skills.map(skill => skill.toLowerCase())
// find all roles which includes any of the given skills
const queryCriteria = {
where: { listOfSkills: { [Op.overlap]: lowerCaseSkills } },
where: where(
fn(
'string_to_array',
fn(
'lower',
fn(
'array_to_string',
col('list_of_skills'),
','
)
),
','
),
{[Op.overlap]: lowerCaseSkills }),
raw: true
}
const roles = await Role.findAll(queryCriteria)
if (roles.length > 0) {
let result = _.each(roles, role => {
// calculate each found roles matching rate
role.skillsMatch = _.intersection(role.listOfSkills, lowerCaseSkills).length / skills.length
// calculate each found roles matching rate (must again be made case-insensitive)
role.skillsMatch = _.intersection(role.listOfSkills.map(skill => skill.toLowerCase()), lowerCaseSkills).length / skills.length
// each role can have multiple rates, get the maximum of global rates
role.maxGlobal = _.maxBy(role.rates, 'global').global
})
Expand Down