Skip to content

Commit 2f9f9b4

Browse files
committed
Member Serach, Stats, ES Config, Joi sort, logger
1 parent ebef2c0 commit 2f9f9b4

12 files changed

+164
-103
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ The following parameters can be set in config files or in env variables:
3535
- ES: config object for Elasticsearch
3636
- ES.HOST: Elasticsearch host
3737
- ES.API_VERSION: Elasticsearch API version
38-
- ES.ES_INDEX: Elasticsearch index name for member
39-
- ES.ES_TYPE: Elasticsearch index type for member
38+
- ES.MEMBER_PROFILE_ES_INDEX: Elasticsearch index name for member profile
39+
- ES.MEMBER_PROFILE_ES_TYPE: Elasticsearch index type for member profile
4040
- ES.MEMBER_TRAIT_ES_INDEX: Elasticsearch index name for member trait
4141
- ES.MEMBER_TRAIT_ES_TYPE: Elasticsearch index type for member trait
42+
- ES.MEMBER_STATS_ES_INDEX: Elasticsearch index name for member stats
43+
- ES.MEMBER_STATS_ES_TYPE: Elasticsearch index type for member stats
44+
- ES.MEMBER_SKILLS_ES_INDEX: Elasticsearch index name for member skills
45+
- ES.MEMBER_SKILLS_ES_TYPE: Elasticsearch index type for member skills
4246
- FILE_UPLOAD_SIZE_LIMIT: the file upload size limit in bytes
4347
- PHOTO_URL_TEMPLATE: photo URL template, its <key> will be replaced with S3 object key
4448
- VERIFY_TOKEN_EXPIRATION: verify token expiration in minutes

app-bootstrap.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ global.Promise = require('bluebird')
55
const Joi = require('joi')
66

77
Joi.page = () => Joi.number().integer().min(1).default(1)
8-
Joi.perPage = () => Joi.number().integer().min(1).max(100).default(20)
8+
Joi.perPage = () => Joi.number().integer().min(1).max(100).default(10)
9+
Joi.sort = () => Joi.string().default("asc")

config/default.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ module.exports = {
4545
HOST: process.env.ES_HOST || 'localhost:9200',
4646
API_VERSION: process.env.ES_API_VERSION || '6.8',
4747
// member index
48-
ES_INDEX: process.env.ES_INDEX || 'members-2020-01',
48+
MEMBER_PROFILE_ES_INDEX: process.env.MEMBER_PROFILE_ES_INDEX || 'members-2020-01',
4949
// member type, ES 6.x accepts only 1 Type per index and it's mandatory to define it
50-
ES_TYPE: process.env.ES_TYPE || 'profiles',
50+
MEMBER_PROFILE_ES_TYPE: process.env.MEMBER_PROFILE_ES_TYPE || 'profiles',
5151
MEMBER_TRAIT_ES_INDEX: process.env.MEMBER_TRAIT_ES_INDEX || 'members-2020-01',
5252
MEMBER_TRAIT_ES_TYPE: process.env.MEMBER_TRAIT_ES_TYPE || 'profiletraits',
5353
MEMBER_STATS_ES_INDEX: process.env.MEMBER_STATS_ES_INDEX || 'memberstats-2020-01',
54-
MEMBER_STATS_ES_TYPE: process.env.MEMBER_STATS_ES_TYPE || 'stats'
54+
MEMBER_STATS_ES_TYPE: process.env.MEMBER_STATS_ES_TYPE || 'stats',
55+
MEMBER_SKILLS_ES_INDEX: process.env.MEMBER_SKILLS_ES_INDEX || 'memberskills-2020-01',
56+
MEMBER_SKILLS_ES_TYPE: process.env.MEMBER_SKILLS_ES_TYPE || 'skills'
5557
},
5658

5759
// health check timeout in milliseconds

src/common/logger.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ logger.decorateWithLogging = (service) => {
8585
const params = method.params || getParams(method)
8686
service[name] = async function () {
8787
logger.debug(`ENTER ${name}`)
88-
logger.debug('input arguments')
89-
const args = Array.prototype.slice.call(arguments)
90-
logger.debug(util.inspect(_sanitizeObject(_combineObject(params, args))))
88+
// logger.debug('input arguments')
89+
// const args = Array.prototype.slice.call(arguments)
90+
// logger.debug(util.inspect(_sanitizeObject(_combineObject(params, args))))
9191
try {
9292
const result = await method.apply(this, arguments)
9393
logger.debug(`EXIT ${name}`)
94-
logger.debug('output arguments')
95-
if (result !== null && result !== undefined) {
96-
logger.debug(util.inspect(_sanitizeObject(result)))
97-
}
94+
// logger.debug('output arguments')
95+
// if (result !== null && result !== undefined) {
96+
// logger.debug(util.inspect(_sanitizeObject(result)))
97+
// }
9898
return result
9999
} catch (e) {
100100
logger.logFullError(e, name)

src/init-es.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const client = helper.getESClient()
1414

1515
const initES = async () => {
1616
if (process.argv.length === 3 && process.argv[2] === 'force') {
17-
logger.info(`Delete index ${config.ES.ES_INDEX} if any.`)
17+
logger.info(`Delete index ${config.ES.MEMBER_PROFILE_ES_INDEX} if any.`)
1818
try {
19-
await client.indices.delete({ index: config.ES.ES_INDEX })
19+
await client.indices.delete({ index: config.ES.MEMBER_PROFILE_ES_INDEX })
2020
} catch (err) {
2121
// ignore
2222
}
@@ -28,14 +28,14 @@ const initES = async () => {
2828
}
2929
}
3030

31-
let exists = await client.indices.exists({ index: config.ES.ES_INDEX })
31+
let exists = await client.indices.exists({ index: config.ES.MEMBER_PROFILE_ES_INDEX })
3232
if (exists) {
33-
logger.info(`The index ${config.ES.ES_INDEX} exists.`)
33+
logger.info(`The index ${config.ES.MEMBER_PROFILE_ES_INDEX} exists.`)
3434
} else {
35-
logger.info(`The index ${config.ES.ES_INDEX} will be created.`)
35+
logger.info(`The index ${config.ES.MEMBER_PROFILE_ES_INDEX} will be created.`)
3636

3737
const body = { mappings: {} }
38-
body.mappings[config.get('ES.ES_TYPE')] = {
38+
body.mappings[config.get('ES.MEMBER_PROFILE_ES_TYPE')] = {
3939
properties: {
4040
handleLower: { type: 'keyword' },
4141
handle: { type: 'keyword' },
@@ -45,7 +45,7 @@ const initES = async () => {
4545
}
4646

4747
await client.indices.create({
48-
index: config.ES.ES_INDEX,
48+
index: config.ES.MEMBER_PROFILE_ES_INDEX,
4949
body
5050
})
5151
}

src/routes.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ module.exports = {
1414
method: 'checkHealth'
1515
}
1616
},
17+
'/members/search/members': {
18+
get: {
19+
controller: 'SearchController',
20+
method: 'searchMembers',
21+
auth: 'jwt',
22+
allowNoToken: true,
23+
scopes: [MEMBERS.READ, MEMBERS.ALL]
24+
}
25+
},
1726
'/members/:handle': {
1827
get: {
1928
controller: 'MemberController',
@@ -120,14 +129,5 @@ module.exports = {
120129
allowNoToken: true,
121130
scopes: [MEMBERS.READ, MEMBERS.ALL]
122131
}
123-
},
124-
'/members': {
125-
get: {
126-
controller: 'SearchController',
127-
method: 'searchMembers',
128-
auth: 'jwt',
129-
allowNoToken: true,
130-
scopes: [MEMBERS.READ, MEMBERS.ALL]
131-
}
132132
}
133133
}

src/scripts/seed-data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ async function seedData () {
390390
await helper.create('Member', member)
391391
// create member in ES
392392
await esClient.create({
393-
index: config.ES.ES_INDEX,
394-
type: config.ES.ES_TYPE,
393+
index: config.ES.MEMBER_PROFILE_ES_INDEX,
394+
type: config.ES.MEMBER_PROFILE_ES_TYPE,
395395
id: member.handleLower,
396396
body: member,
397397
refresh: 'true' // refresh ES so that it is visible for read operations instantly

src/scripts/view-es-data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const esClient = helper.getESClient()
1818
async function showESData () {
1919
const result = await esClient.search({
2020
index: indexName,
21-
type: config.get('ES.ES_TYPE') // type name is same for all indices
21+
type: config.get('ES.MEMBER_PROFILE_ES_TYPE') // type name is same for all indices
2222
})
2323
return result.hits.hits || []
2424
}

src/services/MemberService.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ async function getMember (currentUser, handle, query) {
6262
const selectFields = helper.parseCommaSeparatedString(query.fields, MEMBER_FIELDS) || MEMBER_FIELDS
6363
// query member from Elasticsearch
6464
const esQuery = {
65-
index: config.ES.ES_INDEX,
66-
type: config.ES.ES_TYPE,
65+
index: config.ES.MEMBER_PROFILE_ES_INDEX,
66+
type: config.ES.MEMBER_PROFILE_ES_TYPE,
6767
size: constants.ES_SEARCH_MAX_SIZE, // use a large size to query all records
6868
body: {
6969
query: {
@@ -87,8 +87,12 @@ async function getMember (currentUser, handle, query) {
8787
const memberStatsFields = { "fields": "userId,groupId,handleLower,maxRating" }
8888
const memberStats = await statisticsService.getMemberStats(currentUser, members[i].handleLower,
8989
memberStatsFields, false)
90-
if(memberStats) {
91-
members[i].maxRating = memberStats[0].maxRating
90+
if(memberStats[0]) {
91+
if (memberStats[0].hasOwnProperty("maxRating")) {
92+
members[i].maxRating = memberStats[0].maxRating
93+
} else {
94+
members[i].maxRating = {}
95+
}
9296
}
9397
}
9498
}

0 commit comments

Comments
 (0)