Skip to content

role endpoint added #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ The following parameters can be set in config files or in env variables:
- `topics.TAAS_INTERVIEW_REQUEST_TOPIC`: the request interview entity Kafka message topic
- `topics.TAAS_INTERVIEW_UPDATE_TOPIC`: the update interview entity Kafka message topic
- `topics.TAAS_INTERVIEW_BULK_UPDATE_TOPIC`: the bulk update interview entity Kafka message topic
- `topics.TAAS_ROLE_CREATE_TOPIC`: the create role entity Kafka message topic
- `topics.TAAS_ROLE_UPDATE_TOPIC`: the update role entity Kafka message topic
- `topics.TAAS_ROLE_DELETE_TOPIC`: the delete role entity Kafka message topic
- `esConfig.HOST`: Elasticsearch host
- `esConfig.AWS_REGION`: The Amazon region to use when using AWS Elasticsearch service
- `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
Expand All @@ -46,6 +49,7 @@ The following parameters can be set in config files or in env variables:
- `esConfig.ES_INDEX_JOB`: the index name for job
- `esConfig.ES_INDEX_JOB_CANDIDATE`: the index name for job candidate
- `esConfig.ES_INDEX_RESOURCE_BOOKING`: the index name for resource booking
- `esConfig.ES_INDEX_ROLE`: the index name for role

- `auth0.AUTH0_URL`: Auth0 URL, used to get TC M2M token
- `auth0.AUTH0_AUDIENCE`: Auth0 audience, used to get TC M2M token
Expand Down
12 changes: 9 additions & 3 deletions VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Create documents in ES

- Run the following commands to create `Job`, `JobCandidate`, `Interview`, `ResourceBooking`, `WorkPeriod`, `WorkPeriodPayment` documents in ES.
- Run the following commands to create `Job`, `JobCandidate`, `Interview`, `ResourceBooking`, `WorkPeriod`, `WorkPeriodPayment`, `Role` documents in ES.

``` bash
# for Job
Expand All @@ -17,12 +17,14 @@
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.workperiod.create < test/messages/taas.workperiod.create.event.json
# for WorkPeriodPayment
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.workperiodpayment.create < test/messages/taas.workperiodpayment.create.event.json
# for Role
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.role.requested < test/messages/taas.role.create.event.json
```

- Run `npm run view-data <model-name-here>` to see if documents were created.

## Update documents in ES
- Run the following commands to update `Job`, `JobCandidate`, `Interview`, `ResourceBooking`, `WorkPeriod`, `WorkPeriodPayment` documents in ES.
- Run the following commands to update `Job`, `JobCandidate`, `Interview`, `ResourceBooking`, `WorkPeriod`, `WorkPeriodPayment`, `Role` documents in ES.

``` bash
# for Job
Expand All @@ -37,12 +39,14 @@
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.workperiod.update < test/messages/taas.workperiod.update.event.json
# for WorkPeriodPayment
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.workperiodpayment.update < test/messages/taas.workperiodpayment.update.event.json
# for Role
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.role.update < test/messages/taas.role.update.event.json
```

- Run `npm run view-data <model-name-here>` to see if documents were updated.

## Delete documents in ES
- Run the following commands to delete `Job`, `JobCandidate`, `ResourceBooking`, `WorkPeriod` documents in ES.
- Run the following commands to delete `Job`, `JobCandidate`, `ResourceBooking`, `WorkPeriod`, `Role` documents in ES.

``` bash
# for Job
Expand All @@ -53,6 +57,8 @@
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.resourcebooking.delete < test/messages/taas.resourcebooking.delete.event.json
# for WorkPeriod
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.workperiod.delete < test/messages/taas.workperiod.delete.event.json
# for Role
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.role.delete < test/messages/taas.role.delete.event.json
```

- Run `npm run view-data <model-name-here>` to see if documents were deleted.
9 changes: 7 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ module.exports = {
// topics for interview service
TAAS_INTERVIEW_REQUEST_TOPIC: process.env.TAAS_INTERVIEW_REQUEST_TOPIC || 'taas.interview.requested',
TAAS_INTERVIEW_UPDATE_TOPIC: process.env.TAAS_INTERVIEW_UPDATE_TOPIC || 'taas.interview.update',
TAAS_INTERVIEW_BULK_UPDATE_TOPIC: process.env.TAAS_INTERVIEW_BULK_UPDATE_TOPIC || 'taas.interview.bulkUpdate'
TAAS_INTERVIEW_BULK_UPDATE_TOPIC: process.env.TAAS_INTERVIEW_BULK_UPDATE_TOPIC || 'taas.interview.bulkUpdate',
// topics for role service
TAAS_ROLE_CREATE_TOPIC: process.env.TAAS_ROLE_CREATE_TOPIC || 'taas.role.requested',
TAAS_ROLE_UPDATE_TOPIC: process.env.TAAS_ROLE_UPDATE_TOPIC || 'taas.role.update',
TAAS_ROLE_DELETE_TOPIC: process.env.TAAS_ROLE_DELETE_TOPIC || 'taas.role.delete'
},

esConfig: {
Expand All @@ -54,7 +58,8 @@ module.exports = {

ES_INDEX_JOB: process.env.ES_INDEX_JOB || 'job',
ES_INDEX_JOB_CANDIDATE: process.env.ES_INDEX_JOB_CANDIDATE || 'job_candidate',
ES_INDEX_RESOURCE_BOOKING: process.env.ES_INDEX_RESOURCE_BOOKING || 'resource_booking'
ES_INDEX_RESOURCE_BOOKING: process.env.ES_INDEX_RESOURCE_BOOKING || 'resource_booking',
ES_INDEX_ROLE: process.env.ES_INDEX_ROLE || 'role'
},

auth0: {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ResourceBookingProcessorService = require('./services/ResourceBookingProce
const WorkPeriodProcessorService = require('./services/WorkPeriodProcessorService')
const InterviewProcessorService = require('./services/InterviewProcessorService')
const WorkPeriodPaymentProcessorService = require('./services/WorkPeriodPaymentProcessorService')
const RoleProcessorService = require('./services/RoleProcessorService')
const Mutex = require('async-mutex').Mutex
const events = require('events')

Expand Down Expand Up @@ -52,7 +53,11 @@ const topicServiceMapping = {
// interview
[config.topics.TAAS_INTERVIEW_REQUEST_TOPIC]: InterviewProcessorService.processRequestInterview,
[config.topics.TAAS_INTERVIEW_UPDATE_TOPIC]: InterviewProcessorService.processUpdateInterview,
[config.topics.TAAS_INTERVIEW_BULK_UPDATE_TOPIC]: InterviewProcessorService.processBulkUpdateInterviews
[config.topics.TAAS_INTERVIEW_BULK_UPDATE_TOPIC]: InterviewProcessorService.processBulkUpdateInterviews,
// role
[config.topics.TAAS_ROLE_CREATE_TOPIC]: RoleProcessorService.processCreate,
[config.topics.TAAS_ROLE_UPDATE_TOPIC]: RoleProcessorService.processUpdate,
[config.topics.TAAS_ROLE_DELETE_TOPIC]: RoleProcessorService.processDelete
}

// Start kafka consumer
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Joi.workPeriodPaymentStatus = () => Joi.string().valid('completed', 'cancelled')
// See https://joi.dev/api/?v=17.3.0#string fro details why it's like this.
// In many cases we would like to allow empty string to make it easier to create UI for editing data.
Joi.stringAllowEmpty = () => Joi.string().allow('')
Joi.smallint = () => Joi.number().min(-32768).max(32767)

const zapierSwitch = Joi.string().label('ZAPIER_SWITCH').valid(...Object.values(constants.Zapier.Switch))

Expand Down
34 changes: 34 additions & 0 deletions src/scripts/createIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async function createIndex () {
skills: { type: 'keyword' },
status: { type: 'keyword' },
isApplicationPageActive: { type: 'boolean' },
roleIds: { type: 'keyword' },
createdAt: { type: 'date' },
createdBy: { type: 'keyword' },
updatedAt: { type: 'date' },
Expand Down Expand Up @@ -140,6 +141,39 @@ async function createIndex () {
}
}
}
},
{ index: config.get('esConfig.ES_INDEX_ROLE'),
body: {
mappings: {
properties: {
name: { type: 'keyword' },
description: { type: 'keyword' },
listOfSkills: { type: 'keyword' },
rates: {
properties: {
global: { type: 'integer' },
inCountry: { type: 'integer' },
offShore: { type: 'integer' },
rate30Global: { type: 'integer' },
rate30InCountry: { type: 'integer' },
rate30OffShore: { type: 'integer' },
rate20Global: { type: 'integer' },
rate20InCountry: { type: 'integer' },
rate20OffShore: { type: 'integer' }
}
},
numberOfMembers: { type: 'integer' },
numberOfMembersAvailable: { type: 'integer' },
imageUrl: { type: 'keyword' },
timeToCandidate: { type: 'integer' },
timeToInterview: { type: 'integer' },
createdAt: { type: 'date' },
createdBy: { type: 'keyword' },
updatedAt: { type: 'date' },
updatedBy: { type: 'keyword' }
}
}
}
}
]

Expand Down
3 changes: 2 additions & 1 deletion src/scripts/deleteIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ async function deleteIndex () {
const esClient = helper.getESClient()
const indices = [config.get('esConfig.ES_INDEX_JOB'),
config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
config.get('esConfig.ES_INDEX_RESOURCE_BOOKING')]
config.get('esConfig.ES_INDEX_RESOURCE_BOOKING'),
config.get('esConfig.ES_INDEX_ROLE')]
for (const index of indices) {
await esClient.indices.delete({
index
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/view-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const esClient = helper.getESClient()
const modelIndexMapping = {
Job: 'ES_INDEX_JOB',
JobCandidate: 'ES_INDEX_JOB_CANDIDATE',
ResourceBooking: 'ES_INDEX_RESOURCE_BOOKING'
ResourceBooking: 'ES_INDEX_RESOURCE_BOOKING',
Role: 'ES_INDEX_ROLE'
}

async function showESData () {
Expand Down
3 changes: 2 additions & 1 deletion src/services/JobProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ processCreate.schema = {
updatedAt: Joi.date().allow(null),
updatedBy: Joi.string().uuid().allow(null),
status: Joi.jobStatus().required(),
isApplicationPageActive: Joi.boolean().required()
isApplicationPageActive: Joi.boolean().required(),
roleIds: Joi.array().items(Joi.string().uuid().required()).allow(null)
}).required()
}).required(),
transactionId: Joi.string().required()
Expand Down
119 changes: 119 additions & 0 deletions src/services/RoleProcessorService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Role Processor Service
*/

const Joi = require('@hapi/joi')
const logger = require('../common/logger')
const helper = require('../common/helper')
const constants = require('../common/constants')
const config = require('config')

const esClient = helper.getESClient()

/**
* Process create entity message
* @param {Object} message the kafka message
* @param {String} transactionId
*/
async function processCreate (message, transactionId) {
const role = message.payload
await esClient.createExtra({
index: config.get('esConfig.ES_INDEX_ROLE'),
id: role.id,
transactionId,
body: role,
refresh: constants.esRefreshOption
})
}

processCreate.schema = {
message: Joi.object().keys({
topic: Joi.string().required(),
originator: Joi.string().required(),
timestamp: Joi.date().required(),
'mime-type': Joi.string().required(),
payload: Joi.object().keys({
id: Joi.string().uuid().required(),
name: Joi.string().max(50).required(),
description: Joi.string().max(1000).allow(null),
listOfSkills: Joi.array().items(Joi.string().max(50).required()).allow(null),
rates: Joi.array().items(Joi.object().keys({
global: Joi.smallint().required(),
inCountry: Joi.smallint().required(),
offShore: Joi.smallint().required(),
rate30Global: Joi.smallint().allow(null),
rate30InCountry: Joi.smallint().allow(null),
rate30OffShore: Joi.smallint().allow(null),
rate20Global: Joi.smallint().allow(null),
rate20InCountry: Joi.smallint().allow(null),
rate20OffShore: Joi.smallint().allow(null)
}).required()).required(),
numberOfMembers: Joi.number().allow(null),
numberOfMembersAvailable: Joi.smallint().allow(null),
imageUrl: Joi.string().uri().max(255).allow(null),
timeToCandidate: Joi.smallint().allow(null),
timeToInterview: Joi.smallint().allow(null),
createdAt: Joi.date().required(),
createdBy: Joi.string().uuid().required(),
updatedAt: Joi.date().allow(null),
updatedBy: Joi.string().uuid().allow(null)
}).required()
}).required(),
transactionId: Joi.string().required()
}

/**
* Process update entity message
* @param {Object} message the kafka message
* @param {String} transactionId
*/
async function processUpdate (message, transactionId) {
const data = message.payload
await esClient.updateExtra({
index: config.get('esConfig.ES_INDEX_ROLE'),
id: data.id,
transactionId,
body: {
doc: data
},
refresh: constants.esRefreshOption
})
}

processUpdate.schema = processCreate.schema

/**
* Process delete entity message
* @param {Object} message the kafka message
* @param {String} transactionId
*/
async function processDelete (message, transactionId) {
const id = message.payload.id
await esClient.deleteExtra({
index: config.get('esConfig.ES_INDEX_ROLE'),
id,
transactionId,
refresh: constants.esRefreshOption
})
}

processDelete.schema = {
message: Joi.object().keys({
topic: Joi.string().required(),
originator: Joi.string().required(),
timestamp: Joi.date().required(),
'mime-type': Joi.string().required(),
payload: Joi.object().keys({
id: Joi.string().uuid().required()
}).required()
}).required(),
transactionId: Joi.string().required()
}

module.exports = {
processCreate,
processUpdate,
processDelete
}

logger.buildService(module.exports, 'RoleProcessorService')
5 changes: 5 additions & 0 deletions test/common/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const messages = {
create: { topic: 'taas.workperiodpayment.create', message: require('../messages/taas.workperiodpayment.create.event.json') },
update: { topic: 'taas.workperiodpayment.update', message: require('../messages/taas.workperiodpayment.update.event.json') }
},
Role: {
create: { topic: 'taas.role.requested', message: require('../messages/taas.role.create.event.json') },
update: { topic: 'taas.role.update', message: require('../messages/taas.role.update.event.json') },
delete: { topic: 'taas.role.delete', message: require('../messages/taas.role.delete.event .json') }
},
messageInvalid: '{ "topic": "taas.job.create", }'
}

Expand Down
5 changes: 4 additions & 1 deletion test/messages/taas.job.create.event.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"createdAt": "2020-11-05T19:00:16.268Z",
"createdBy": "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a",
"status": "sourcing",
"isApplicationPageActive": false
"isApplicationPageActive": false,
"roleIds": [
"e7b7e818-40d4-4102-b486-09bdd21400b8"
]
}
}
5 changes: 4 additions & 1 deletion test/messages/taas.job.update.event.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"updatedBy": "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a",
"createdAt": "2020-11-05T19:00:16.268Z",
"createdBy": "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a",
"isApplicationPageActive": false
"isApplicationPageActive": false,
"roleIds": [
"e7b7e818-40d4-4102-b486-09bdd21400b8"
]
}
}
Loading