@@ -84,8 +84,8 @@ function getPathname () {
8484 * Process single job data. The processing consists of:
8585 * - Validate the data.
8686 * - Skip processing if externalId is missing.
87- * - Create a job if it is not already exists .
88- * - Create a resource booking if it is not already exists .
87+ * - Create a job if it does not already exist .
88+ * - Create a resource booking if it does not already exist .
8989 * - Update the resourceBooking based on startDate and endDate.
9090 *
9191 * @param {Object } job the job data
@@ -96,47 +96,47 @@ async function processJob (job, info = []) {
9696 // validate the data
9797 const { value : data , error } = validateJob ( job )
9898 if ( error ) {
99- info . push ( error . details [ 0 ] . message )
99+ info . push ( { text : error . details [ 0 ] . message , tag : 'validation_error' } )
100100 return { status : constants . ProcessingStatus . Failed , info }
101101 }
102102 if ( ! data . externalId ) {
103- info . push ( 'externalId is missing' )
103+ info . push ( { text : 'externalId is missing' , tag : 'external_id_missing' } )
104104 return { status : constants . ProcessingStatus . Skipped , info }
105105 }
106106 data . projectId = ( await helper . getProjectByDirectProjectId ( data . directProjectId ) ) . id
107- // create a job if it is not already exists
107+ // create a job if it does not already exist
108108 try {
109109 const result = await helper . getJobByExternalId ( data . externalId )
110- info . push ( `id: ${ result . id } externalId: ${ data . externalId } job already exists` )
110+ info . push ( { text : `id: ${ result . id } externalId: ${ data . externalId } job already exists` , tag : 'job_already_exists' } )
111111 data . jobId = result . id
112112 } catch ( err ) {
113113 if ( ! ( err . message && err . message . includes ( 'job not found' ) ) ) {
114114 throw err
115115 }
116116 const result = await helper . createJob ( _ . pick ( data , [ 'projectId' , 'externalId' , 'title' , 'numPositions' , 'skills' ] ) )
117- info . push ( `id: ${ result . id } job created` )
117+ info . push ( { text : `id: ${ result . id } job created` , tag : 'job_created' } )
118118 data . jobId = result . id
119119 }
120120 data . userId = ( await helper . getUserByHandle ( data . userHandle ) ) . id
121121 logger . debug ( `userHandle: ${ data . userHandle } userId: ${ data . userId } ` )
122- // create a resource booking if it is not already exists
122+ // create a resource booking if it does not already exist
123123 try {
124124 const result = await helper . getResourceBookingByJobIdAndUserId ( data . jobId , data . userId )
125- info . push ( `id: ${ result . id } resource booking already exists` )
125+ info . push ( { text : `id: ${ result . id } resource booking already exists` , tag : 'resource_booking_already_exists' } )
126126 return { status : constants . ProcessingStatus . Successful , info }
127127 } catch ( err ) {
128128 if ( ! ( err . message && err . message . includes ( 'resource booking not found' ) ) ) {
129129 throw err
130130 }
131131 const result = await helper . createResourceBooking ( _ . pick ( data , [ 'projectId' , 'jobId' , 'userId' , 'startDate' , 'endDate' , 'memberRate' , 'customerRate' , 'rateType' ] ) )
132- info . push ( `id: ${ result . id } resource booking created` )
132+ info . push ( { text : `id: ${ result . id } resource booking created` , tag : 'resource_booking_created' } )
133133 data . resourceBookingId = result . id
134134 }
135135 // update the resourceBooking based on startDate and endDate
136136 const resourceBookingStatus = dateFNS . compareAsc ( new Date ( data . startDate ) , new Date ( data . endDate ) ) === 1 ? 'closed' : 'assigned'
137137 logger . debug ( `resourceBookingId: ${ data . resourceBookingId } status: ${ resourceBookingStatus } ` )
138138 await helper . updateResourceBookingStatus ( data . resourceBookingId , resourceBookingStatus )
139- info . push ( `id: ${ data . resourceBookingId } status: ${ resourceBookingStatus } resource booking updated` )
139+ info . push ( { text : `id: ${ data . resourceBookingId } status: ${ resourceBookingStatus } resource booking updated` , tag : 'resource_booking_status_updated' } )
140140 return { status : constants . ProcessingStatus . Successful , info }
141141}
142142
@@ -156,9 +156,9 @@ async function main () {
156156 report . add ( { lnum : job . _lnum , ...result } )
157157 } catch ( err ) {
158158 if ( err . response ) {
159- report . add ( { lnum : job . _lnum , status : constants . ProcessingStatus . Failed , info : [ err . response . error . toString ( ) . split ( '\n' ) [ 0 ] ] } )
159+ report . add ( { lnum : job . _lnum , status : constants . ProcessingStatus . Failed , info : [ { text : err . response . error . toString ( ) . split ( '\n' ) [ 0 ] , tag : 'request_error' } ] } )
160160 } else {
161- report . add ( { lnum : job . _lnum , status : constants . ProcessingStatus . Failed , info : [ err . message ] } )
161+ report . add ( { lnum : job . _lnum , status : constants . ProcessingStatus . Failed , info : [ { text : err . message , tag : 'internal_error' } ] } )
162162 }
163163 }
164164 report . print ( )
0 commit comments