|
2 | 2 | * Interview Processor Service |
3 | 3 | */ |
4 | 4 |
|
| 5 | +const _ = require('lodash') |
5 | 6 | const Joi = require('@hapi/joi') |
6 | 7 | const logger = require('../common/logger') |
7 | 8 | const helper = require('../common/helper') |
@@ -66,14 +67,74 @@ processRequestInterview.schema = { |
66 | 67 | createdAt: Joi.date().required(), |
67 | 68 | createdBy: Joi.string().uuid().required(), |
68 | 69 | updatedAt: Joi.date().allow(null), |
69 | | - updatedBy: Joi.string().uuid().allow(null) |
| 70 | + updatedBy: Joi.string().uuid().allow(null), |
| 71 | + attendeesList: Joi.array().items(Joi.string().email()).allow(null), |
| 72 | + startTimestamp: Joi.date().allow(null) |
| 73 | + }).required() |
| 74 | + }).required(), |
| 75 | + transactionId: Joi.string().required() |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * Process update interview entity message. |
| 80 | + * Update an interview record under jobCandidate. |
| 81 | + * |
| 82 | + * @param {Object} message the kafka message |
| 83 | + * @param {String} transactionId |
| 84 | + */ |
| 85 | +async function processUpdateInterview (message, transactionId) { |
| 86 | + const data = message.payload |
| 87 | + const { body: jobCandidate } = await esClient.getExtra({ |
| 88 | + index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'), |
| 89 | + id: data.jobCandidateId |
| 90 | + }) |
| 91 | + const interviews = jobCandidate.interviews || [] |
| 92 | + const index = _.findIndex(interviews, ['id', data.id]) |
| 93 | + if (index === -1) { |
| 94 | + interviews.push(data) |
| 95 | + } else { |
| 96 | + interviews.splice(index, 1, data) |
| 97 | + } |
| 98 | + jobCandidate.interviews = interviews |
| 99 | + await esClient.updateExtra({ |
| 100 | + index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'), |
| 101 | + id: data.jobCandidateId, |
| 102 | + transactionId, |
| 103 | + body: { |
| 104 | + doc: jobCandidate |
| 105 | + }, |
| 106 | + refresh: constants.esRefreshOption |
| 107 | + }) |
| 108 | +} |
| 109 | + |
| 110 | +processUpdateInterview.schema = { |
| 111 | + message: Joi.object().keys({ |
| 112 | + topic: Joi.string().required(), |
| 113 | + originator: Joi.string().required(), |
| 114 | + timestamp: Joi.date().required(), |
| 115 | + 'mime-type': Joi.string().required(), |
| 116 | + payload: Joi.object().keys({ |
| 117 | + id: Joi.string().uuid().required(), |
| 118 | + jobCandidateId: Joi.string().uuid().required(), |
| 119 | + googleCalendarId: Joi.string().allow(null), |
| 120 | + customMessage: Joi.string().allow(null), |
| 121 | + xaiTemplate: Joi.string().required(), |
| 122 | + round: Joi.number().integer().positive().required(), |
| 123 | + status: Joi.interviewStatus().required(), |
| 124 | + createdAt: Joi.date().required(), |
| 125 | + createdBy: Joi.string().uuid().required(), |
| 126 | + updatedAt: Joi.date().required(), |
| 127 | + updatedBy: Joi.string().uuid().required(), |
| 128 | + attendeesList: Joi.array().items(Joi.string().email()).allow(null), |
| 129 | + startTimestamp: Joi.date().allow(null) |
70 | 130 | }).required() |
71 | 131 | }).required(), |
72 | 132 | transactionId: Joi.string().required() |
73 | 133 | } |
74 | 134 |
|
75 | 135 | module.exports = { |
76 | | - processRequestInterview |
| 136 | + processRequestInterview, |
| 137 | + processUpdateInterview |
77 | 138 | } |
78 | 139 |
|
79 | 140 | logger.buildService(module.exports, 'InterviewProcessorService') |
0 commit comments