Skip to content

Commit ad305a3

Browse files
author
Aranyajit
committed
fix host user id and swagger document along with ubahn removal
1 parent 1d8f83d commit ad305a3

File tree

10 files changed

+48
-91
lines changed

10 files changed

+48
-91
lines changed

config/default.js

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module.exports = {
1515
AUTH0_URL: process.env.AUTH0_URL,
1616
// Auth0 audience, used to get TC M2M token
1717
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
18-
// Auth0 audience for U-Bahn
19-
AUTH0_AUDIENCE_UBAHN: process.env.AUTH0_AUDIENCE_UBAHN,
2018
// Auth0 token cache time, used to get TC M2M token
2119
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
2220
// Auth0 client id, used to get TC M2M token

docs/swagger.yaml

+33-33
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ paths:
635635
required: false
636636
schema:
637637
type: string
638-
format: uuid
638+
example: '443211'
639+
description: 'The topcoder user id'
639640
description: The user id.
640641
- in: query
641642
name: status
@@ -1654,7 +1655,8 @@ paths:
16541655
required: false
16551656
schema:
16561657
type: string
1657-
format: uuid
1658+
example: '443211'
1659+
description: 'The topcoder user id'
16581660
description: The job id.
16591661
- in: query
16601662
name: projectId
@@ -3186,11 +3188,11 @@ paths:
31863188
parameters:
31873189
- in: path
31883190
name: userId
3189-
description: The userId
3191+
description: 'The topcoder user id'
31903192
required: true
31913193
schema:
31923194
type: string
3193-
format: uuid
3195+
example: '443211'
31943196

31953197
responses:
31963198
"200":
@@ -3243,11 +3245,12 @@ paths:
32433245
parameters:
32443246
- in: path
32453247
name: userId
3246-
description: The UUID of the User whose calendar should be deleted
3248+
description: The topcoder id of the User whose calendar should be deleted
32473249
required: true
32483250
schema:
32493251
type: string
3250-
format: uuid
3252+
example: '443211'
3253+
description: 'The topcoder user id'
32513254
- in: path
32523255
name: calendarId
32533256
description: The id of the calendar to delete. This id comes from Nylas backend server
@@ -4518,9 +4521,8 @@ components:
45184521
description: "The project id."
45194522
userId:
45204523
type: string
4521-
format: uuid
4522-
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
4523-
description: "The user id."
4524+
example: '443211'
4525+
description: "The topcoder user id."
45244526
status:
45254527
type: string
45264528
enum:
@@ -4589,9 +4591,8 @@ components:
45894591
description: "The project id."
45904592
userId:
45914593
type: string
4592-
format: uuid
4593-
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
4594-
description: "The user id."
4594+
example: '443211'
4595+
description: "The topcoder user id."
45954596
status:
45964597
type: string
45974598
enum:
@@ -4678,9 +4679,8 @@ components:
46784679
description: "The project id."
46794680
userId:
46804681
type: string
4681-
format: uuid
4682-
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
4683-
description: "The user id."
4682+
example: '443211'
4683+
description: "The topcoder user id."
46844684
status:
46854685
type: string
46864686
enum:
@@ -4862,8 +4862,8 @@ components:
48624862
description: "The handle of the interview host"
48634863
hostUserId:
48644864
type: string
4865-
example: "00000000-0000-0000-0000-000000000000"
4866-
description: "The userId of the interview host"
4865+
example: "442321"
4866+
description: "The topcoder userId of the interview host"
48674867
jobCandidateId:
48684868
type: string
48694869
format: uuid
@@ -4949,7 +4949,8 @@ components:
49494949
pattern: "^[0-9]{1,2}:[0-9]{2}$"
49504950
hostUserId:
49514951
type: string
4952-
format: uuid
4952+
example: '443211'
4953+
description: 'The topcoder user id of the host'
49534954

49544955
UpdateInterviewByRequestBody:
49554956
properties:
@@ -4962,7 +4963,7 @@ components:
49624963
example: "Europe/London"
49634964
hostUserId:
49644965
type: string
4965-
description: "UUID of interview host user"
4966+
description: "The topcoder id of interview host user"
49664967
expireTimestamp:
49674968
type: string
49684969
format: date-time
@@ -5122,9 +5123,8 @@ components:
51225123
description: "The project id."
51235124
userId:
51245125
type: string
5125-
format: uuid
5126-
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
5127-
description: "The external id."
5126+
example: "442312"
5127+
description: "The topcoder id."
51285128
jobId:
51295129
type: string
51305130
format: uuid
@@ -5206,9 +5206,8 @@ components:
52065206
description: "The project id."
52075207
userId:
52085208
type: string
5209-
format: uuid
5210-
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
5211-
description: "The external id."
5209+
example: "442321"
5210+
description: "The topcoder id."
52125211
sendWeeklySurvey:
52135212
type: boolean
52145213
example: true,
@@ -5566,8 +5565,8 @@ components:
55665565
description: The job id.
55675566
userId:
55685567
type: string
5569-
format: uuid
5570-
description: The user id.
5568+
example: '442321'
5569+
description: 'The topcoder user id'
55715570
projectId:
55725571
type: integer
55735572
description: The project id.
@@ -5779,8 +5778,8 @@ components:
57795778
description: "The resource booking id."
57805779
userId:
57815780
type: string
5782-
format: uuid
5783-
description: "The user id."
5781+
example: '442321'
5782+
description: "The topcoder user id."
57845783
handle:
57855784
type: string
57865785
example: "Tony"
@@ -6023,8 +6022,8 @@ components:
60236022
description: "The job candidate id."
60246023
userId:
60256024
type: string
6026-
format: uuid
6027-
description: "User id."
6025+
example: '44231'
6026+
description: "The topcoder user id."
60286027
resume:
60296028
type: string
60306029
format: url
@@ -6369,7 +6368,7 @@ components:
63696368
userId:
63706369
type: number
63716370
example: 40157055
6372-
description: the user id
6371+
description: 'The topcoder user id'
63736372
handle:
63746373
type: string
63756374
example: maxceemdev
@@ -6701,7 +6700,8 @@ components:
67016700
properties:
67026701
userId:
67036702
type: string
6704-
format: uuid
6703+
example: '442321'
6704+
description: 'The topcoder user id'
67056705
defaultAvailableTime:
67066706
type: array
67076707
items:

scripts/demo-email-notifications/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ async function resetNotificationRecords () {
7575

7676
const interviewForReminder = await Interview.findById('a23e1bf2-1084-4cfe-a0d8-d83bc6fec655')
7777
// update hostUserId to test user phash_manager
78-
await interviewForReminder.update({ createdAt: moment().subtract(moment.duration(config.INTERVIEW_REMINDER_DAY_AFTER)).toDate(), hostUserId: '57646ff9-1cd3-4d3c-88ba-eb09a395366c' })
78+
await interviewForReminder.update({ createdAt: moment().subtract(moment.duration(config.INTERVIEW_REMINDER_DAY_AFTER)).toDate(), hostUserId: '14848314' })
7979

8080
const interviewExpired = await Interview.findById('505db942-79fe-4b6f-974c-b359e1b61967')
81-
await interviewExpired.update({ expireTimestamp: moment().subtract(moment.duration(1, 'days')).toDate(), hostUserId: '57646ff9-1cd3-4d3c-88ba-eb09a395366c' })
81+
await interviewExpired.update({ expireTimestamp: moment().subtract(moment.duration(1, 'days')).toDate(), hostUserId: '14848314' })
8282

8383
// reset upcoming resource booking expiration records
8484
localLogger.info('reset upcoming resource booking expiration records')

src/common/helper.js

+1-41
Original file line numberDiff line numberDiff line change
@@ -469,45 +469,6 @@ async function getProjects (currentUser, criteria = {}) {
469469
}
470470
}
471471

472-
/**
473-
* Function to get users
474-
* @param {String} userId the user UUID
475-
* @returns the found user details
476-
*/
477-
async function getUserDetailsByUserUUID (userUUID) {
478-
const token = await getM2MToken()
479-
const res = await request
480-
.get(`${config.TC_API}/users/${userUUID}?enrich=true`)
481-
.set('Authorization', `Bearer ${token}`)
482-
.set('Content-Type', 'application/json')
483-
.set('Accept', 'application/json')
484-
localLogger.debug({
485-
context: 'getUserById',
486-
message: `response body: ${JSON.stringify(res.body)}`
487-
})
488-
const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName', 'externalProfiles'])
489-
490-
if (!_.isUndefined(user.externalProfiles) && !_.isEmpty(user.externalProfiles)) {
491-
_.assign(user, { userId: _.toInteger(_.get(user.externalProfiles[0], 'externalId')) })
492-
}
493-
494-
const handleQuery = `handleLower:${user.handle.toLowerCase()}`
495-
const userIdQuery = `userId:${user.userId}`
496-
497-
const query = _.concat(handleQuery, userIdQuery).join(URI.encodeQuery(' OR ', 'utf8'))
498-
try {
499-
const searchResult = await searchUsersByQuery(query)
500-
const found = _.find(searchResult, !_.isUndefined(user.handle)
501-
? ['handle', user.handle] : ['userId', user.userId]) || {}
502-
503-
return found
504-
} catch (err) {
505-
const error = new Error(err.response.text)
506-
error.status = err.status
507-
throw error
508-
}
509-
}
510-
511472
/**
512473
* Search users by query string.
513474
* @param {String} query the query string
@@ -620,7 +581,7 @@ async function getProjectById (currentUser, id) {
620581
* @returns the request result
621582
*/
622583
async function getTopcoderSkills (criteria) {
623-
const token = await getM2MUbahnToken()
584+
const token = await getM2MToken()
624585
try {
625586
const res = await request
626587
.get(`${config.TC_API}/skills`)
@@ -1650,7 +1611,6 @@ module.exports = {
16501611
getEmailTemplatesForKey,
16511612
formatDate,
16521613
formatDateTimeEDT,
1653-
getUserDetailsByUserUUID,
16541614
runExclusiveCalendarConnectionHandler,
16551615
waitForUnlockCalendarConnectionHandler,
16561616
runExclusiveInterviewEventHandler,

src/models/Interview.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ module.exports = (sequelize) => {
100100
availableTime: nylasAvailableTimeSchema('availableTime'),
101101
hostUserId: {
102102
field: 'hostUserId',
103-
type: Sequelize.UUID,
104-
allowNull: false
103+
type: Sequelize.TEXT
105104
},
106105
expireTimestamp: {
107106
field: 'expireTimestamp',

src/services/InterviewService.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ async function requestInterview (currentUser, jobCandidateId, interview) {
166166

167167
// if M2M require hostUserId
168168
if (currentUser.isMachine) {
169-
const hostUserIdValidator = Joi.string().uuid().required()
169+
const hostUserIdValidator = Joi.string().required()
170170
const { error } = hostUserIdValidator.validate(interview.hostUserId)
171171
if (error) {
172-
throw new errors.BadRequestError(`interview.hostUserId ${interview.hostUserId} is required and must be a valid uuid`)
172+
throw new errors.BadRequestError(`interview.hostUserId ${interview.hostUserId} is required and must be a valid topcoder user id`)
173173
}
174174
}
175175

@@ -203,7 +203,7 @@ async function requestInterview (currentUser, jobCandidateId, interview) {
203203
// get calendar if exists, otherwise create a virtual one for the user
204204
const existentCalendar = await UserMeetingSettings.getPrimaryNylasCalendarForUser(interview.hostUserId)
205205
if (_.isNil(existentCalendar)) {
206-
const { email, firstName, lastName } = await helper.getUserDetailsByUserUUID(interview.hostUserId)
206+
const { email, firstName, lastName } = await helper.ensureTopcoderUserIdExists(interview.hostUserId)
207207
const currentUserFullname = `${firstName} ${lastName}`
208208
calendar = await createVirtualCalendarForUser(interview.hostUserId, email, currentUserFullname, interview.hostTimezone)
209209
// make the new calendar primary
@@ -290,7 +290,7 @@ requestInterview.schema = Joi.object().keys({
290290
interview: Joi.object().keys({
291291
duration: Joi.number().integer().positive().required(),
292292
hostTimezone: Joi.string().required(),
293-
hostUserId: Joi.string().uuid(),
293+
hostUserId: Joi.string(),
294294
expireTimestamp: Joi.date(),
295295
availableTime: Joi.array().min(1).items(
296296
Joi.object({
@@ -400,7 +400,7 @@ partiallyUpdateInterviewByRound.schema = Joi.object().keys({
400400
data: Joi.object().keys({
401401
duration: Joi.number().integer().positive(),
402402
hostTimezone: Joi.string(),
403-
hostUserId: Joi.string().uuid(),
403+
hostUserId: Joi.string(),
404404
expireTimestamp: Joi.date(),
405405
availableTime: Joi.array().min(1).items(
406406
Joi.object({
@@ -448,7 +448,7 @@ partiallyUpdateInterviewById.schema = Joi.object().keys({
448448
data: Joi.object().keys({
449449
duration: Joi.number().integer().positive(),
450450
hostTimezone: Joi.string(),
451-
hostUserId: Joi.string().uuid(),
451+
hostUserId: Joi.string(),
452452
expireTimestamp: Joi.date(),
453453
availableTime: Joi.array().min(1).items(
454454
Joi.object({

src/services/NotificationsSchedulerService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ async function getDataForInterview (interview, jobCandidate, job) {
9595

9696
job = job || await Job.findById(jobCandidate.jobId)
9797

98-
const hostUserDetails = await helper.getUserDetailsByUserUUID(interview.hostUserId)
99-
const userDetails = await helper.getUserDetailsByUserUUID(jobCandidate.userId)
98+
const hostUserDetails = await helper.ensureTopcoderUserIdExists(interview.hostUserId)
99+
const userDetails = await helper.ensureTopcoderUserIdExists(jobCandidate.userId)
100100
let tcUser
101101
try {
102102
tcUser = await helper.ensureTopcoderUserIdExists(jobCandidate.userId)

src/services/NylasWebhookService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async function processCalendarCreatedWebhook (webhookData, webhookId) {
297297

298298
// NOTE, that we cannot use `userId` because it's UUID, while in
299299
// `currentUser` we need to have integer user id
300-
const user = _.pick(await helper.getUserDetailsByUserUUID(userMeetingSettingsForCalendar.id), ['userId', 'handle'])
300+
const user = _.pick(await helper.ensureTopcoderUserIdExists(userMeetingSettingsForCalendar.id), ['userId', 'handle'])
301301

302302
await UserMeetingSettingsService.syncUserMeetingsSettings(user, {
303303
id: userMeetingSettingsForCalendar.id,

src/services/TeamService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ async function getTeamJob (currentUser, id, jobId) {
429429
})
430430

431431
// request host user details only one time if all interview are hosted by the same host
432-
const hostUserDetails = await Promise.all(_.map(_.keys(hostMap), hostId => helper.getUserDetailsByUserUUID(hostId)))
432+
const hostUserDetails = await Promise.all(_.map(_.keys(hostMap), hostId => helper.ensureTopcoderUserIdExists(hostId)))
433433
_.map(_.keys(hostMap), (hostId, index) => {
434434
hostMap[hostId] = hostUserDetails[index]
435435
})

src/services/UserMeetingSettingsService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ async function handleConnectCalendarCallback (reqQuery) {
292292
// as a current user use the user who is connecting the calendar
293293
// NOTE, that we cannot use `userId` because it's UUID, while in
294294
// `currentUser` we need to have integer user id
295-
const currentUser = _.pick(await helper.getUserDetailsByUserUUID(userId), ['userId', 'handle'])
295+
const currentUser = _.pick(await helper.ensureTopcoderUserIdExists(userId), ['userId', 'handle'])
296296

297297
await syncUserMeetingsSettings(
298298
currentUser,

0 commit comments

Comments
 (0)