Skip to content

Commit f3f20f3

Browse files
authored
2 parents e66100c + 015a796 commit f3f20f3

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
@@ -918,7 +918,6 @@ async function getSkillIdsByNames (skills) {
918918
// endpoint returns the partial matched skills
919919
// we need to filter by exact match case insensitive
920920
const filteredSkills = _.filter(result, tcSkill => _.some(skills, skill => _.toLower(skill) === _.toLower(tcSkill.name)))
921-
console.log(filteredSkills)
922921
const skillIds = _.map(filteredSkills, 'id')
923922
return skillIds
924923
}
@@ -1014,41 +1013,33 @@ async function createTeam (currentUser, data) {
10141013
const projectRequestBody = {
10151014
name: data.teamName,
10161015
description: data.teamDescription,
1017-
type: 'app_dev',
1016+
type: 'talent-as-a-service',
10181017
details: {
10191018
positions: data.positions
10201019
}
10211020
}
10221021
// create project with given data
1023-
const project = await helper.createProject(projectRequestBody)
1024-
// we created the project with m2m token
1025-
// so we have to add the current user as a member to the project
1026-
// the role of the user in the project will be determined by user's current roles.
1027-
if (!currentUser.isMachine) {
1028-
await helper.createProjectMember(project.id, { userId: currentUser.userId })
1029-
}
1022+
const project = await helper.createProject(currentUser, projectRequestBody)
10301023
// create jobs for the given positions.
10311024
await Promise.all(_.map(data.positions, async position => {
10321025
const roleSearchRequest = roleSearchRequests[position.roleSearchRequestId]
10331026
const job = {
10341027
projectId: project.id,
10351028
title: position.roleName,
10361029
numPositions: position.numberOfResources,
1037-
rateType: 'weekly',
1038-
skills: roleSearchRequest.skills
1039-
}
1040-
if (roleSearchRequest.jobDescription) {
1041-
job.description = roleSearchRequest.jobDescription
1030+
rateType: position.rateType,
1031+
workload: position.workload,
1032+
skills: roleSearchRequest.skills,
1033+
description: roleSearchRequest.jobDescription,
1034+
roleIds: [roleSearchRequest.roleId],
1035+
resourceType: roleSearchRequest.resourceType
10421036
}
10431037
if (position.startMonth) {
10441038
job.startDate = position.startMonth
10451039
}
10461040
if (position.durationWeeks) {
10471041
job.duration = position.durationWeeks
10481042
}
1049-
if (roleSearchRequest.roleId) {
1050-
job.roleIds = [roleSearchRequest.roleId]
1051-
}
10521043
await JobService.createJob(currentUser, job)
10531044
}))
10541045
return { projectId: project.id }
@@ -1066,7 +1057,10 @@ createTeam.schema = Joi.object()
10661057
roleSearchRequestId: Joi.string().uuid().required(),
10671058
numberOfResources: Joi.number().integer().min(1).required(),
10681059
durationWeeks: Joi.number().integer().min(1),
1069-
startMonth: Joi.date()
1060+
startMonth: Joi.date(),
1061+
rateType: Joi.rateType().default('weekly'),
1062+
workload: Joi.workload().default('full-time'),
1063+
resourceType: Joi.string()
10701064
}).required()
10711065
).required()
10721066
}).required()
@@ -1084,19 +1078,23 @@ async function _validateRoleSearchRequests (roleSearchRequestIds) {
10841078
const roleSearchRequest = await RoleSearchRequest.findById(roleSearchRequestId)
10851079
// store the found roleSearchRequest to avoid unnecessary DB calls
10861080
roleSearchRequests[roleSearchRequestId] = roleSearchRequest.toJSON()
1087-
// we can't create a job without skills
1088-
if (!roleSearchRequest.roleId && !roleSearchRequest.skills) {
1089-
throw new errors.ConflictError(`roleSearchRequestId: ${roleSearchRequestId} must have roleId or skills`)
1081+
// we can't create a job without a role
1082+
if (!roleSearchRequest.roleId) {
1083+
throw new errors.ConflictError(`roleSearchRequestId: ${roleSearchRequestId} must have roleId`)
10901084
}
1085+
const role = await Role.findById(roleSearchRequest.roleId)
10911086
// if roleSearchRequest doesn't have skills, we have to get skills through role
10921087
if (!roleSearchRequest.skills) {
1093-
const role = await Role.findById(roleSearchRequest.roleId)
10941088
if (!role.listOfSkills) {
10951089
throw new errors.ConflictError(`role: ${role.id} must have skills`)
10961090
}
1097-
// store the found skills
1091+
// store role's skills
10981092
roleSearchRequests[roleSearchRequestId].skills = await getSkillIdsByNames(role.listOfSkills)
10991093
}
1094+
if (!roleSearchRequest.jobDescription) {
1095+
roleSearchRequests[roleSearchRequestId].jobDescription = role.description
1096+
}
1097+
roleSearchRequests[roleSearchRequestId].resourceType = role.name
11001098
}))
11011099
return roleSearchRequests
11021100
}

0 commit comments

Comments
 (0)