Skip to content

Role quick fixes - Project and Jobs data #351

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 16, 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
6 changes: 3 additions & 3 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1867,11 +1867,11 @@ async function getTags (description) {
* @param {Object} data title of project and any other info
* @returns {Object} the project created
*/
async function createProject (data) {
const token = await getM2MToken()
async function createProject (currentUser, data) {
const token = currentUser.jwtToken
const res = await request
.post(`${config.TC_API}/projects/`)
.set('Authorization', `Bearer ${token}`)
.set('Authorization', token)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(data)
Expand Down
44 changes: 21 additions & 23 deletions src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ async function getSkillIdsByNames (skills) {
// endpoint returns the partial matched skills
// we need to filter by exact match case insensitive
const filteredSkills = _.filter(result, tcSkill => _.some(skills, skill => _.toLower(skill) === _.toLower(tcSkill.name)))
console.log(filteredSkills)
const skillIds = _.map(filteredSkills, 'id')
return skillIds
}
Expand Down Expand Up @@ -1014,41 +1013,33 @@ async function createTeam (currentUser, data) {
const projectRequestBody = {
name: data.teamName,
description: data.teamDescription,
type: 'app_dev',
type: 'talent-as-a-service',
details: {
positions: data.positions
}
}
// create project with given data
const project = await helper.createProject(projectRequestBody)
// we created the project with m2m token
// so we have to add the current user as a member to the project
// the role of the user in the project will be determined by user's current roles.
if (!currentUser.isMachine) {
await helper.createProjectMember(project.id, { userId: currentUser.userId })
}
const project = await helper.createProject(currentUser, projectRequestBody)
// create jobs for the given positions.
await Promise.all(_.map(data.positions, async position => {
const roleSearchRequest = roleSearchRequests[position.roleSearchRequestId]
const job = {
projectId: project.id,
title: position.roleName,
numPositions: position.numberOfResources,
rateType: 'weekly',
skills: roleSearchRequest.skills
}
if (roleSearchRequest.jobDescription) {
job.description = roleSearchRequest.jobDescription
rateType: position.rateType,
workload: position.workload,
skills: roleSearchRequest.skills,
description: roleSearchRequest.jobDescription,
roleIds: [roleSearchRequest.roleId],
resourceType: roleSearchRequest.resourceType
}
if (position.startMonth) {
job.startDate = position.startMonth
}
if (position.durationWeeks) {
job.duration = position.durationWeeks
}
if (roleSearchRequest.roleId) {
job.roleIds = [roleSearchRequest.roleId]
}
await JobService.createJob(currentUser, job)
}))
return { projectId: project.id }
Expand All @@ -1066,7 +1057,10 @@ createTeam.schema = Joi.object()
roleSearchRequestId: Joi.string().uuid().required(),
numberOfResources: Joi.number().integer().min(1).required(),
durationWeeks: Joi.number().integer().min(1),
startMonth: Joi.date()
startMonth: Joi.date(),
rateType: Joi.rateType().default('weekly'),
workload: Joi.workload().default('full-time'),
resourceType: Joi.string()
}).required()
).required()
}).required()
Expand All @@ -1084,19 +1078,23 @@ async function _validateRoleSearchRequests (roleSearchRequestIds) {
const roleSearchRequest = await RoleSearchRequest.findById(roleSearchRequestId)
// store the found roleSearchRequest to avoid unnecessary DB calls
roleSearchRequests[roleSearchRequestId] = roleSearchRequest.toJSON()
// we can't create a job without skills
if (!roleSearchRequest.roleId && !roleSearchRequest.skills) {
throw new errors.ConflictError(`roleSearchRequestId: ${roleSearchRequestId} must have roleId or skills`)
// we can't create a job without a role
if (!roleSearchRequest.roleId) {
throw new errors.ConflictError(`roleSearchRequestId: ${roleSearchRequestId} must have roleId`)
}
const role = await Role.findById(roleSearchRequest.roleId)
// if roleSearchRequest doesn't have skills, we have to get skills through role
if (!roleSearchRequest.skills) {
const role = await Role.findById(roleSearchRequest.roleId)
if (!role.listOfSkills) {
throw new errors.ConflictError(`role: ${role.id} must have skills`)
}
// store the found skills
// store role's skills
roleSearchRequests[roleSearchRequestId].skills = await getSkillIdsByNames(role.listOfSkills)
}
if (!roleSearchRequest.jobDescription) {
roleSearchRequests[roleSearchRequestId].jobDescription = role.description
}
roleSearchRequests[roleSearchRequestId].resourceType = role.name
}))
return roleSearchRequests
}
Expand Down