Skip to content

Commit 1979d3f

Browse files
Merge pull request #50 from topcoder-platform/dev-wp
[PROD] Release 1.6.0
2 parents eac7ee0 + 95800c8 commit 1979d3f

20 files changed

+440
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ coverage
55
.DS_Store
66
.env
77
api.env
8+
.eslintrc.y*ml

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ The following parameters can be set in config files or in env variables:
3030
- `topics.TAAS_RESOURCE_BOOKING_CREATE_TOPIC`: the create resource booking entity Kafka message topic
3131
- `topics.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC`: the update resource booking entity Kafka message topic
3232
- `topics.TAAS_RESOURCE_BOOKING_DELETE_TOPIC`: the delete resource booking entity Kafka message topic
33+
- `topics.TAAS_WORK_PERIOD_CREATE_TOPIC`: the create work period entity Kafka message topic
34+
- `topics.TAAS_WORK_PERIOD_UPDATE_TOPIC`: the update work period entity Kafka message topic
35+
- `topics.TAAS_WORK_PERIOD_DELETE_TOPIC`: the delete work period entity Kafka message topic
36+
- `topics.TAAS_WORK_PERIOD_PAYMENT_CREATE_TOPIC`: the create work period payment entity Kafka message topic
37+
- `topics.TAAS_WORK_PERIOD_PAYMENT_UPDATE_TOPIC`: the update work period payment entity Kafka message topic
3338
- `esConfig.HOST`: Elasticsearch host
3439
- `esConfig.AWS_REGION`: The Amazon region to use when using AWS Elasticsearch service
3540
- `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
@@ -38,6 +43,7 @@ The following parameters can be set in config files or in env variables:
3843
- `esConfig.ES_INDEX_JOB`: the index name for job
3944
- `esConfig.ES_INDEX_JOB_CANDIDATE`: the index name for job candidate
4045
- `esConfig.ES_INDEX_RESOURCE_BOOKING`: the index name for resource booking
46+
- `esConfig.ES_INDEX_WORK_PERIOD`: the index name for work period
4147

4248
- `auth0.AUTH0_URL`: Auth0 URL, used to get TC M2M token
4349
- `auth0.AUTH0_AUDIENCE`: Auth0 audience, used to get TC M2M token

VERIFICATION.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Create documents in ES
44

5-
- Run the following commands to create `Job`, `JobCandidate` and `ResourceBooking` documents in ES.
5+
- Run the following commands to create `Job`, `JobCandidate`, `ResourceBooking`, `WorkPeriod`, `WorkPeriodPayment` documents in ES.
66

77
``` bash
88
# for Job
@@ -11,12 +11,16 @@
1111
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.jobcandidate.create < test/messages/taas.jobcandidate.create.event.json
1212
# for ResourceBooking
1313
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.resourcebooking.create < test/messages/taas.resourcebooking.create.event.json
14+
# for WorkPeriod
15+
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
16+
# for WorkPeriodPayment
17+
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
1418
```
1519

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

1822
## Update documents in ES
19-
- Run the following commands to update `Job`, `JobCandidate` and `ResourceBooking` documents in ES.
23+
- Run the following commands to update `Job`, `JobCandidate`, `ResourceBooking`, `WorkPeriod`, `WorkPeriodPayment` documents in ES.
2024

2125
``` bash
2226
# for Job
@@ -25,12 +29,16 @@
2529
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.jobcandidate.update < test/messages/taas.jobcandidate.update.event.json
2630
# for ResourceBooking
2731
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.resourcebooking.update < test/messages/taas.resourcebooking.update.event.json
32+
# for WorkPeriod
33+
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
34+
# for WorkPeriodPayment
35+
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
2836
```
2937

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

3240
## Delete documents in ES
33-
- Run the following commands to delete `Job`, `JobCandidate` and `ResourceBooking` documents in ES.
41+
- Run the following commands to delete `Job`, `JobCandidate`, `ResourceBooking`, `WorkPeriod` documents in ES.
3442

3543
``` bash
3644
# for Job
@@ -39,6 +47,8 @@
3947
docker exec -i taas-es-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic taas.jobcandidate.delete < test/messages/taas.jobcandidate.delete.event.json
4048
# for ResourceBooking
4149
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
50+
# for WorkPeriod
51+
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
4252
```
4353

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

config/default.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,25 @@ module.exports = {
1616
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'taas-es-processor',
1717

1818
topics: {
19+
// topics for job service
1920
TAAS_JOB_CREATE_TOPIC: process.env.TAAS_JOB_CREATE_TOPIC || 'taas.job.create',
2021
TAAS_JOB_UPDATE_TOPIC: process.env.TAAS_JOB_UPDATE_TOPIC || 'taas.job.update',
2122
TAAS_JOB_DELETE_TOPIC: process.env.TAAS_JOB_DELETE_TOPIC || 'taas.job.delete',
2223
// topics for jobcandidate service
2324
TAAS_JOB_CANDIDATE_CREATE_TOPIC: process.env.TAAS_JOB_CANDIDATE_CREATE_TOPIC || 'taas.jobcandidate.create',
2425
TAAS_JOB_CANDIDATE_UPDATE_TOPIC: process.env.TAAS_JOB_CANDIDATE_UPDATE_TOPIC || 'taas.jobcandidate.update',
2526
TAAS_JOB_CANDIDATE_DELETE_TOPIC: process.env.TAAS_JOB_CANDIDATE_DELETE_TOPIC || 'taas.jobcandidate.delete',
26-
// topics for job service
27+
// topics for resource booking service
2728
TAAS_RESOURCE_BOOKING_CREATE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_CREATE_TOPIC || 'taas.resourcebooking.create',
2829
TAAS_RESOURCE_BOOKING_UPDATE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC || 'taas.resourcebooking.update',
29-
TAAS_RESOURCE_BOOKING_DELETE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_DELETE_TOPIC || 'taas.resourcebooking.delete'
30+
TAAS_RESOURCE_BOOKING_DELETE_TOPIC: process.env.TAAS_RESOURCE_BOOKING_DELETE_TOPIC || 'taas.resourcebooking.delete',
31+
// topics for work period service
32+
TAAS_WORK_PERIOD_CREATE_TOPIC: process.env.TAAS_WORK_PERIOD_CREATE_TOPIC || 'taas.workperiod.create',
33+
TAAS_WORK_PERIOD_UPDATE_TOPIC: process.env.TAAS_WORK_PERIOD_UPDATE_TOPIC || 'taas.workperiod.update',
34+
TAAS_WORK_PERIOD_DELETE_TOPIC: process.env.TAAS_WORK_PERIOD_DELETE_TOPIC || 'taas.workperiod.delete',
35+
// topics for work period payment service
36+
TAAS_WORK_PERIOD_PAYMENT_CREATE_TOPIC: process.env.TAAS_WORK_PERIOD_PAYMENT_CREATE_TOPIC || 'taas.workperiodpayment.create',
37+
TAAS_WORK_PERIOD_PAYMENT_UPDATE_TOPIC: process.env.TAAS_WORK_PERIOD_PAYMENT_UPDATE_TOPIC || 'taas.workperiodpayment.update'
3038
},
3139

3240
esConfig: {
@@ -42,7 +50,8 @@ module.exports = {
4250

4351
ES_INDEX_JOB: process.env.ES_INDEX_JOB || 'job',
4452
ES_INDEX_JOB_CANDIDATE: process.env.ES_INDEX_JOB_CANDIDATE || 'job_candidate',
45-
ES_INDEX_RESOURCE_BOOKING: process.env.ES_INDEX_RESOURCE_BOOKING || 'resource_booking'
53+
ES_INDEX_RESOURCE_BOOKING: process.env.ES_INDEX_RESOURCE_BOOKING || 'resource_booking',
54+
ES_INDEX_WORK_PERIOD: process.env.ES_INDEX_WORK_PERIOD || 'work_period'
4655
},
4756

4857
auth0: {

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.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.workperiod.create:1:1,taas.workperiodpayment.create:1:1,taas.job.update:1:1,taas.jobcandidate.update:1:1,taas.resourcebooking.update:1:1,taas.workperiod.update:1:1,taas.workperiodpayment.update:1:1,taas.job.delete:1:1,taas.jobcandidate.delete:1:1,taas.resourcebooking.delete:1:1,taas.workperiod.delete:1:1"
1616
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1717
esearch:
1818
image: elasticsearch:7.7.1

src/app.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const helper = require('./common/helper')
1212
const JobProcessorService = require('./services/JobProcessorService')
1313
const JobCandidateProcessorService = require('./services/JobCandidateProcessorService')
1414
const ResourceBookingProcessorService = require('./services/ResourceBookingProcessorService')
15+
const WorkPeriodProcessorService = require('./services/WorkPeriodProcessorService')
16+
const WorkPeriodPaymentProcessorService = require('./services/WorkPeriodPaymentProcessorService')
1517
const Mutex = require('async-mutex').Mutex
1618
const events = require('events')
1719

@@ -38,7 +40,14 @@ const topicServiceMapping = {
3840
// resource booking
3941
[config.topics.TAAS_RESOURCE_BOOKING_CREATE_TOPIC]: ResourceBookingProcessorService.processCreate,
4042
[config.topics.TAAS_RESOURCE_BOOKING_UPDATE_TOPIC]: ResourceBookingProcessorService.processUpdate,
41-
[config.topics.TAAS_RESOURCE_BOOKING_DELETE_TOPIC]: ResourceBookingProcessorService.processDelete
43+
[config.topics.TAAS_RESOURCE_BOOKING_DELETE_TOPIC]: ResourceBookingProcessorService.processDelete,
44+
// work period
45+
[config.topics.TAAS_WORK_PERIOD_CREATE_TOPIC]: WorkPeriodProcessorService.processCreate,
46+
[config.topics.TAAS_WORK_PERIOD_UPDATE_TOPIC]: WorkPeriodProcessorService.processUpdate,
47+
[config.topics.TAAS_WORK_PERIOD_DELETE_TOPIC]: WorkPeriodProcessorService.processDelete,
48+
// work period payment
49+
[config.topics.TAAS_WORK_PERIOD_PAYMENT_CREATE_TOPIC]: WorkPeriodPaymentProcessorService.processCreate,
50+
[config.topics.TAAS_WORK_PERIOD_PAYMENT_UPDATE_TOPIC]: WorkPeriodPaymentProcessorService.processUpdate
4251
}
4352

4453
// Start kafka consumer

src/bootstrap.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ global.Promise = require('bluebird')
66

77
Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
88
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
9+
Joi.resourceBookingStatus = () => Joi.string().valid('assigned', 'closed', 'cancelled')
910
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled', 'interview', 'topcoder-rejected')
1011
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
1112
Joi.title = () => Joi.string().max(128)
13+
Joi.paymentStatus = () => Joi.string().valid('pending', 'partially-completed', 'completed', 'cancelled')
14+
Joi.workPeriodPaymentStatus = () => Joi.string().valid('completed', 'cancelled')
1215
// Empty string is not allowed by Joi by default and must be enabled with allow('').
1316
// See https://joi.dev/api/?v=17.3.0#string fro details why it's like this.
1417
// In many cases we would like to allow empty string to make it easier to create UI for editing data.

src/scripts/createIndex.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,49 @@ async function createIndex () {
6363
userId: { type: 'keyword' },
6464
jobId: { type: 'keyword' },
6565
status: { type: 'keyword' },
66-
startDate: { type: 'date' },
67-
endDate: { type: 'date' },
66+
startDate: { type: 'date', format: 'yyyy-MM-dd' },
67+
endDate: { type: 'date', format: 'yyyy-MM-dd' },
6868
memberRate: { type: 'float' },
6969
customerRate: { type: 'float' },
7070
rateType: { type: 'keyword' },
71+
billingAccountId: { type: 'integer' },
72+
createdAt: { type: 'date' },
73+
createdBy: { type: 'keyword' },
74+
updatedAt: { type: 'date' },
75+
updatedBy: { type: 'keyword' }
76+
}
77+
}
78+
}
79+
},
80+
{
81+
index: config.get('esConfig.ES_INDEX_WORK_PERIOD'),
82+
body: {
83+
mappings: {
84+
properties: {
85+
resourceBookingId: { type: 'keyword' },
86+
userHandle: { type: 'keyword' },
87+
projectId: { type: 'integer' },
88+
userId: { type: 'keyword' },
89+
startDate: { type: 'date', format: 'yyyy-MM-dd' },
90+
endDate: { type: 'date', format: 'yyyy-MM-dd' },
91+
daysWorked: { type: 'integer' },
92+
memberRate: { type: 'float' },
93+
customerRate: { type: 'float' },
94+
paymentStatus: { type: 'keyword' },
95+
payments: {
96+
type: 'nested',
97+
properties: {
98+
workPeriodId: { type: 'keyword' },
99+
challengeId: { type: 'keyword' },
100+
amount: { type: 'float' },
101+
status: { type: 'keyword' },
102+
billingAccountId: { type: 'integer' },
103+
createdAt: { type: 'date' },
104+
createdBy: { type: 'keyword' },
105+
updatedAt: { type: 'date' },
106+
updatedBy: { type: 'keyword' }
107+
}
108+
},
71109
createdAt: { type: 'date' },
72110
createdBy: { type: 'keyword' },
73111
updatedAt: { type: 'date' },

src/scripts/deleteIndex.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ async function deleteIndex () {
1111
const esClient = helper.getESClient()
1212
const indices = [config.get('esConfig.ES_INDEX_JOB'),
1313
config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
14-
config.get('esConfig.ES_INDEX_RESOURCE_BOOKING')]
14+
config.get('esConfig.ES_INDEX_RESOURCE_BOOKING'),
15+
config.get('esConfig.ES_INDEX_WORK_PERIOD')]
1516
for (const index of indices) {
1617
await esClient.indices.delete({
1718
index

src/scripts/view-data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const esClient = helper.getESClient()
1111
const modelIndexMapping = {
1212
Job: 'ES_INDEX_JOB',
1313
JobCandidate: 'ES_INDEX_JOB_CANDIDATE',
14-
ResourceBooking: 'ES_INDEX_RESOURCE_BOOKING'
14+
ResourceBooking: 'ES_INDEX_RESOURCE_BOOKING',
15+
WorkPeriod: 'ES_INDEX_WORK_PERIOD'
1516
}
1617

1718
async function showESData () {

0 commit comments

Comments
 (0)