Skip to content

Commit 47ae415

Browse files
committed
part2
1 parent 130d37a commit 47ae415

File tree

7 files changed

+77
-6
lines changed

7 files changed

+77
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following parameters can be set in config files or in env variables:
3434
- `topics.TAAS_WORK_PERIOD_UPDATE_TOPIC`: the update work period entity Kafka message topic
3535
- `topics.TAAS_WORK_PERIOD_DELETE_TOPIC`: the delete work period entity Kafka message topic
3636
- `topics.TAAS_INTERVIEW_REQUEST_TOPIC`: the request interview entity Kafka message topic
37+
- `topics.TAAS_INTERVIEW_UPDATE_TOPIC`: the update interview entity Kafka message topic
3738
- `esConfig.HOST`: Elasticsearch host
3839
- `esConfig.AWS_REGION`: The Amazon region to use when using AWS Elasticsearch service
3940
- `esConfig.ELASTICCLOUD.id`: The elastic cloud id, if your elasticsearch instance is hosted on elastic cloud. DO NOT provide a value for ES_HOST if you are using this

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module.exports = {
3333
TAAS_WORK_PERIOD_UPDATE_TOPIC: process.env.TAAS_WORK_PERIOD_UPDATE_TOPIC || 'taas.workperiod.update',
3434
TAAS_WORK_PERIOD_DELETE_TOPIC: process.env.TAAS_WORK_PERIOD_DELETE_TOPIC || 'taas.workperiod.delete',
3535
// topics for interview service
36-
TAAS_INTERVIEW_REQUEST_TOPIC: process.env.TAAS_INTERVIEW_REQUEST_TOPIC || 'taas.interview.request'
36+
TAAS_INTERVIEW_REQUEST_TOPIC: process.env.TAAS_INTERVIEW_REQUEST_TOPIC || 'taas.interview.requested',
37+
TAAS_INTERVIEW_UPDATE_TOPIC: process.env.TAAS_INTERVIEW_UPDATE_TOPIC || 'taas.interview.update'
3738
},
3839

3940
esConfig: {

local/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
- "9092:9092"
1313
environment:
1414
KAFKA_ADVERTISED_HOST_NAME: localhost
15-
KAFKA_CREATE_TOPICS: "taas.job.create:1:1,taas.jobcandidate.create:1:1,taas.resourcebooking.create:1:1,taas.interview.request:1:1,taas.job.update:1:1,taas.jobcandidate.update:1:1,taas.resourcebooking.update:1:1,taas.job.delete:1:1,taas.jobcandidate.delete:1:1,taas.resourcebooking.delete:1:1"
15+
KAFKA_CREATE_TOPICS: "taas.job.create:1:1,taas.jobcandidate.create:1:1,taas.resourcebooking.create:1:1,taas.interview.requested:1:1,taas.interview.update:1:1,taas.job.update:1:1,taas.jobcandidate.update:1:1,taas.resourcebooking.update:1:1,taas.job.delete:1:1,taas.jobcandidate.delete:1:1,taas.resourcebooking.delete:1:1"
1616
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1717
esearch:
1818
image: elasticsearch:7.7.1

src/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const topicServiceMapping = {
4646
[config.topics.TAAS_WORK_PERIOD_UPDATE_TOPIC]: WorkPeriodProcessorService.processUpdate,
4747
[config.topics.TAAS_WORK_PERIOD_DELETE_TOPIC]: WorkPeriodProcessorService.processDelete,
4848
// interview
49-
[config.topics.TAAS_INTERVIEW_REQUEST_TOPIC]: InterviewProcessorService.processRequestInterview
49+
[config.topics.TAAS_INTERVIEW_REQUEST_TOPIC]: InterviewProcessorService.processRequestInterview,
50+
[config.topics.TAAS_INTERVIEW_UPDATE_TOPIC]: InterviewProcessorService.processUpdateInterview
5051
}
5152

5253
// Start kafka consumer

src/common/constants.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ module.exports = {
1919
},
2020
Interview: {
2121
Status: {
22-
Requested: 'Requested'
22+
Scheduling: 'Scheduling',
23+
Scheduled: 'Scheduled',
24+
RequestedForReschedule: 'Requested for reschedule',
25+
Rescheduled: 'Rescheduled',
26+
Completed: 'Completed',
27+
Cancelled: 'Cancelled'
2328
}
2429
}
2530
}

src/scripts/createIndex.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ async function createIndex () {
5252
id: { type: 'keyword' },
5353
jobCandidateId: { type: 'keyword' },
5454
googleCalendarId: { type: 'keyword' },
55+
startTimestamp: { type: 'date' },
56+
attendeesList: { type: 'keyword' },
5557
customMessage: { type: 'text' },
5658
xaiTemplate: { type: 'keyword' },
5759
round: { type: 'integer' },

src/services/InterviewProcessorService.js

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Interview Processor Service
33
*/
44

5+
const _ = require('lodash')
56
const Joi = require('@hapi/joi')
67
const logger = require('../common/logger')
78
const helper = require('../common/helper')
@@ -66,14 +67,74 @@ processRequestInterview.schema = {
6667
createdAt: Joi.date().required(),
6768
createdBy: Joi.string().uuid().required(),
6869
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)
70130
}).required()
71131
}).required(),
72132
transactionId: Joi.string().required()
73133
}
74134

75135
module.exports = {
76-
processRequestInterview
136+
processRequestInterview,
137+
processUpdateInterview
77138
}
78139

79140
logger.buildService(module.exports, 'InterviewProcessorService')

0 commit comments

Comments
 (0)