@@ -6,7 +6,6 @@ import Joi from 'joi';
6
6
import Promise from 'bluebird' ;
7
7
import config from 'config' ;
8
8
import axios from 'axios' ;
9
- import moment from 'moment' ;
10
9
import util from '../../util' ;
11
10
import models from '../../models' ;
12
11
import { createPhaseTopic } from '../projectPhases' ;
@@ -175,7 +174,6 @@ async function projectCreatedKafkaHandler(app, topic, payload) {
175
174
if ( result . error ) {
176
175
throw new Error ( result . error ) ;
177
176
}
178
-
179
177
const project = payload ;
180
178
181
179
if ( project . phases && project . phases . length > 0 ) {
@@ -187,46 +185,41 @@ async function projectCreatedKafkaHandler(app, topic, payload) {
187
185
await Promise . all ( topicPromises ) ;
188
186
app . logger . debug ( 'Topics for phases are successfully created.' ) ;
189
187
}
190
- // TODO: temporary disable this feature, until we release TaaS APP
191
- if ( false === true && project . type === 'talent-as-a-service' ) {
192
- const specialists = _ . get ( project , 'details.taasDefinition.specialists' ) ;
193
- if ( ! specialists || ! specialists . length ) {
194
- app . logger . debug ( `no specialists found in the project ${ project . id } ` ) ;
195
- return ;
188
+ try {
189
+ if ( project . type === 'talent-as-a-service' ) {
190
+ const jobs = _ . get ( project , 'details.taasDefinition.taasJobs' ) ;
191
+ if ( ! jobs || ! jobs . length ) {
192
+ app . logger . debug ( `no jobs found in the project id: ${ project . id } ` ) ;
193
+ return ;
194
+ }
195
+ app . logger . debug ( `${ jobs . length } jobs found in the project id: ${ project . id } ` ) ;
196
+ await Promise . all (
197
+ _ . map (
198
+ jobs ,
199
+ ( job ) => {
200
+ // make sure that skills would be unique in the list and only include ones with 'skillId' (actually they all suppose to be with skillId)
201
+ const skills = _ . chain ( job . skills ) . map ( 'skillId' ) . uniq ( ) . compact ( )
202
+ . value ( ) ;
203
+ return createTaasJob ( {
204
+ projectId : project . id ,
205
+ title : job . title ,
206
+ description : job . description ,
207
+ skills,
208
+ numPositions : Number ( job . people ) ,
209
+ resourceType : _ . get ( job , 'role.value' , '' ) ,
210
+ rateType : 'weekly' , // hardcode for now
211
+ workload : _ . get ( job , 'workLoad.title' , '' ) . toLowerCase ( ) ,
212
+ } ) . then ( ( createdJob ) => {
213
+ app . logger . debug ( `jobId: ${ createdJob . id } job created with title "${ createdJob . title } "` ) ;
214
+ } ) . catch ( ( err ) => {
215
+ app . logger . error ( `Unable to create job with title "${ job . title } ": ${ err . message } ` ) ;
216
+ } ) ;
217
+ } ,
218
+ ) ,
219
+ ) ;
196
220
}
197
- const targetSpecialists = _ . filter ( specialists , specialist => Number ( specialist . people ) > 0 ) ; // must be at least one people
198
- await Promise . all (
199
- _ . map (
200
- targetSpecialists ,
201
- ( specialist ) => {
202
- const startDate = new Date ( ) ;
203
- const endDate = moment ( startDate ) . add ( Number ( specialist . duration ) , 'M' ) ; // the unit of duration is month
204
- // make sure that skills would be unique in the list
205
- const skills = _ . uniq (
206
- // use both, required and additional skills for jobs
207
- specialist . skills . concat ( specialist . additionalSkills )
208
- // only include skills with `skillId` and ignore custom skills in jobs
209
- . filter ( skill => skill . skillId ) . map ( skill => skill . skillId ) ,
210
- ) ;
211
- return createTaasJob ( {
212
- projectId : project . id ,
213
- externalId : '0' , // hardcode for now
214
- description : specialist . roleTitle ,
215
- startDate,
216
- endDate,
217
- skills,
218
- numPositions : Number ( specialist . people ) ,
219
- resourceType : specialist . role ,
220
- rateType : 'hourly' , // hardcode for now
221
- workload : _ . get ( specialist , 'workLoad.title' , '' ) . toLowerCase ( ) ,
222
- } ) . then ( ( job ) => {
223
- app . logger . debug ( `jobId: ${ job . id } job created for roleTitle ${ specialist . roleTitle } ` ) ;
224
- } ) . catch ( ( err ) => {
225
- app . logger . error ( `Unable to create job for ${ specialist . roleTitle } : ${ err . message } ` ) ;
226
- } ) ;
227
- } ,
228
- ) ,
229
- ) ;
221
+ } catch ( error ) {
222
+ app . logger . error ( `Error while creating TaaS jobs: ${ error } ` ) ;
230
223
}
231
224
}
232
225
0 commit comments