@@ -84,8 +84,8 @@ function getPathname () {
84
84
* Process single job data. The processing consists of:
85
85
* - Validate the data.
86
86
* - 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 .
89
89
* - Update the resourceBooking based on startDate and endDate.
90
90
*
91
91
* @param {Object } job the job data
@@ -96,47 +96,47 @@ async function processJob (job, info = []) {
96
96
// validate the data
97
97
const { value : data , error } = validateJob ( job )
98
98
if ( error ) {
99
- info . push ( error . details [ 0 ] . message )
99
+ info . push ( { text : error . details [ 0 ] . message , tag : 'validation_error' } )
100
100
return { status : constants . ProcessingStatus . Failed , info }
101
101
}
102
102
if ( ! data . externalId ) {
103
- info . push ( 'externalId is missing' )
103
+ info . push ( { text : 'externalId is missing' , tag : 'external_id_missing' } )
104
104
return { status : constants . ProcessingStatus . Skipped , info }
105
105
}
106
106
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
108
108
try {
109
109
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' } )
111
111
data . jobId = result . id
112
112
} catch ( err ) {
113
113
if ( ! ( err . message && err . message . includes ( 'job not found' ) ) ) {
114
114
throw err
115
115
}
116
116
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' } )
118
118
data . jobId = result . id
119
119
}
120
120
data . userId = ( await helper . getUserByHandle ( data . userHandle ) ) . id
121
121
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
123
123
try {
124
124
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' } )
126
126
return { status : constants . ProcessingStatus . Successful , info }
127
127
} catch ( err ) {
128
128
if ( ! ( err . message && err . message . includes ( 'resource booking not found' ) ) ) {
129
129
throw err
130
130
}
131
131
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' } )
133
133
data . resourceBookingId = result . id
134
134
}
135
135
// update the resourceBooking based on startDate and endDate
136
136
const resourceBookingStatus = dateFNS . compareAsc ( new Date ( data . startDate ) , new Date ( data . endDate ) ) === 1 ? 'closed' : 'assigned'
137
137
logger . debug ( `resourceBookingId: ${ data . resourceBookingId } status: ${ resourceBookingStatus } ` )
138
138
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' } )
140
140
return { status : constants . ProcessingStatus . Successful , info }
141
141
}
142
142
@@ -156,9 +156,9 @@ async function main () {
156
156
report . add ( { lnum : job . _lnum , ...result } )
157
157
} catch ( err ) {
158
158
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' } ] } )
160
160
} 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' } ] } )
162
162
}
163
163
}
164
164
report . print ( )
0 commit comments