Skip to content

Commit acd1e0b

Browse files
authored
Merge pull request #351 from topcoder-platform/role-quick-fixes
Role quick fixes - create Project and Jobs data in Connect and TaaS on Submit Request
2 parents 8249acc + f3f20f3 commit acd1e0b

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/common/helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,11 +1867,11 @@ async function getTags (description) {
18671867
* @param {Object} data title of project and any other info
18681868
* @returns {Object} the project created
18691869
*/
1870-
async function createProject (data) {
1871-
const token = await getM2MToken()
1870+
async function createProject (currentUser, data) {
1871+
const token = currentUser.jwtToken
18721872
const res = await request
18731873
.post(`${config.TC_API}/projects/`)
1874-
.set('Authorization', `Bearer ${token}`)
1874+
.set('Authorization', token)
18751875
.set('Content-Type', 'application/json')
18761876
.set('Accept', 'application/json')
18771877
.send(data)

src/services/TeamService.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,6 @@ async function getSkillIdsByNames (skills) {
922922
// endpoint returns the partial matched skills
923923
// we need to filter by exact match case insensitive
924924
const filteredSkills = _.filter(result, tcSkill => _.some(skills, skill => _.toLower(skill) === _.toLower(tcSkill.name)))
925-
console.log(filteredSkills)
926925
const skillIds = _.map(filteredSkills, 'id')
927926
return skillIds
928927
}
@@ -1018,41 +1017,33 @@ async function createTeam (currentUser, data) {
10181017
const projectRequestBody = {
10191018
name: data.teamName,
10201019
description: data.teamDescription,
1021-
type: 'app_dev',
1020+
type: 'talent-as-a-service',
10221021
details: {
10231022
positions: data.positions
10241023
}
10251024
}
10261025
// create project with given data
1027-
const project = await helper.createProject(projectRequestBody)
1028-
// we created the project with m2m token
1029-
// so we have to add the current user as a member to the project
1030-
// the role of the user in the project will be determined by user's current roles.
1031-
if (!currentUser.isMachine) {
1032-
await helper.createProjectMember(project.id, { userId: currentUser.userId })
1033-
}
1026+
const project = await helper.createProject(currentUser, projectRequestBody)
10341027
// create jobs for the given positions.
10351028
await Promise.all(_.map(data.positions, async position => {
10361029
const roleSearchRequest = roleSearchRequests[position.roleSearchRequestId]
10371030
const job = {
10381031
projectId: project.id,
10391032
title: position.roleName,
10401033
numPositions: position.numberOfResources,
1041-
rateType: 'weekly',
1042-
skills: roleSearchRequest.skills
1043-
}
1044-
if (roleSearchRequest.jobDescription) {
1045-
job.description = roleSearchRequest.jobDescription
1034+
rateType: position.rateType,
1035+
workload: position.workload,
1036+
skills: roleSearchRequest.skills,
1037+
description: roleSearchRequest.jobDescription,
1038+
roleIds: [roleSearchRequest.roleId],
1039+
resourceType: roleSearchRequest.resourceType
10461040
}
10471041
if (position.startMonth) {
10481042
job.startDate = position.startMonth
10491043
}
10501044
if (position.durationWeeks) {
10511045
job.duration = position.durationWeeks
10521046
}
1053-
if (roleSearchRequest.roleId) {
1054-
job.roleIds = [roleSearchRequest.roleId]
1055-
}
10561047
await JobService.createJob(currentUser, job)
10571048
}))
10581049
return { projectId: project.id }
@@ -1070,7 +1061,10 @@ createTeam.schema = Joi.object()
10701061
roleSearchRequestId: Joi.string().uuid().required(),
10711062
numberOfResources: Joi.number().integer().min(1).required(),
10721063
durationWeeks: Joi.number().integer().min(1),
1073-
startMonth: Joi.date()
1064+
startMonth: Joi.date(),
1065+
rateType: Joi.rateType().default('weekly'),
1066+
workload: Joi.workload().default('full-time'),
1067+
resourceType: Joi.string()
10741068
}).required()
10751069
).required()
10761070
}).required()
@@ -1088,19 +1082,23 @@ async function _validateRoleSearchRequests (roleSearchRequestIds) {
10881082
const roleSearchRequest = await RoleSearchRequest.findById(roleSearchRequestId)
10891083
// store the found roleSearchRequest to avoid unnecessary DB calls
10901084
roleSearchRequests[roleSearchRequestId] = roleSearchRequest.toJSON()
1091-
// we can't create a job without skills
1092-
if (!roleSearchRequest.roleId && !roleSearchRequest.skills) {
1093-
throw new errors.ConflictError(`roleSearchRequestId: ${roleSearchRequestId} must have roleId or skills`)
1085+
// we can't create a job without a role
1086+
if (!roleSearchRequest.roleId) {
1087+
throw new errors.ConflictError(`roleSearchRequestId: ${roleSearchRequestId} must have roleId`)
10941088
}
1089+
const role = await Role.findById(roleSearchRequest.roleId)
10951090
// if roleSearchRequest doesn't have skills, we have to get skills through role
10961091
if (!roleSearchRequest.skills) {
1097-
const role = await Role.findById(roleSearchRequest.roleId)
10981092
if (!role.listOfSkills) {
10991093
throw new errors.ConflictError(`role: ${role.id} must have skills`)
11001094
}
1101-
// store the found skills
1095+
// store role's skills
11021096
roleSearchRequests[roleSearchRequestId].skills = await getSkillIdsByNames(role.listOfSkills)
11031097
}
1098+
if (!roleSearchRequest.jobDescription) {
1099+
roleSearchRequests[roleSearchRequestId].jobDescription = role.description
1100+
}
1101+
roleSearchRequests[roleSearchRequestId].resourceType = role.name
11041102
}))
11051103
return roleSearchRequests
11061104
}

0 commit comments

Comments
 (0)