Skip to content

Commit

Permalink
fix host user id and swagger document along with ubahn removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Aranyajit committed Jan 29, 2024
1 parent 1d8f83d commit ad305a3
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 91 deletions.
2 changes: 0 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ module.exports = {
AUTH0_URL: process.env.AUTH0_URL,
// Auth0 audience, used to get TC M2M token
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
// Auth0 audience for U-Bahn
AUTH0_AUDIENCE_UBAHN: process.env.AUTH0_AUDIENCE_UBAHN,
// Auth0 token cache time, used to get TC M2M token
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
// Auth0 client id, used to get TC M2M token
Expand Down
66 changes: 33 additions & 33 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ paths:
required: false
schema:
type: string
format: uuid
example: '443211'
description: 'The topcoder user id'
description: The user id.
- in: query
name: status
Expand Down Expand Up @@ -1654,7 +1655,8 @@ paths:
required: false
schema:
type: string
format: uuid
example: '443211'
description: 'The topcoder user id'
description: The job id.
- in: query
name: projectId
Expand Down Expand Up @@ -3186,11 +3188,11 @@ paths:
parameters:
- in: path
name: userId
description: The userId
description: 'The topcoder user id'
required: true
schema:
type: string
format: uuid
example: '443211'

responses:
"200":
Expand Down Expand Up @@ -3243,11 +3245,12 @@ paths:
parameters:
- in: path
name: userId
description: The UUID of the User whose calendar should be deleted
description: The topcoder id of the User whose calendar should be deleted
required: true
schema:
type: string
format: uuid
example: '443211'
description: 'The topcoder user id'
- in: path
name: calendarId
description: The id of the calendar to delete. This id comes from Nylas backend server
Expand Down Expand Up @@ -4518,9 +4521,8 @@ components:
description: "The project id."
userId:
type: string
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The user id."
example: '443211'
description: "The topcoder user id."
status:
type: string
enum:
Expand Down Expand Up @@ -4589,9 +4591,8 @@ components:
description: "The project id."
userId:
type: string
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The user id."
example: '443211'
description: "The topcoder user id."
status:
type: string
enum:
Expand Down Expand Up @@ -4678,9 +4679,8 @@ components:
description: "The project id."
userId:
type: string
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The user id."
example: '443211'
description: "The topcoder user id."
status:
type: string
enum:
Expand Down Expand Up @@ -4862,8 +4862,8 @@ components:
description: "The handle of the interview host"
hostUserId:
type: string
example: "00000000-0000-0000-0000-000000000000"
description: "The userId of the interview host"
example: "442321"
description: "The topcoder userId of the interview host"
jobCandidateId:
type: string
format: uuid
Expand Down Expand Up @@ -4949,7 +4949,8 @@ components:
pattern: "^[0-9]{1,2}:[0-9]{2}$"
hostUserId:
type: string
format: uuid
example: '443211'
description: 'The topcoder user id of the host'

UpdateInterviewByRequestBody:
properties:
Expand All @@ -4962,7 +4963,7 @@ components:
example: "Europe/London"
hostUserId:
type: string
description: "UUID of interview host user"
description: "The topcoder id of interview host user"
expireTimestamp:
type: string
format: date-time
Expand Down Expand Up @@ -5122,9 +5123,8 @@ components:
description: "The project id."
userId:
type: string
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The external id."
example: "442312"
description: "The topcoder id."
jobId:
type: string
format: uuid
Expand Down Expand Up @@ -5206,9 +5206,8 @@ components:
description: "The project id."
userId:
type: string
format: uuid
example: "a55fe1bc-1754-45fa-9adc-cf3d6d7c377a"
description: "The external id."
example: "442321"
description: "The topcoder id."
sendWeeklySurvey:
type: boolean
example: true,
Expand Down Expand Up @@ -5566,8 +5565,8 @@ components:
description: The job id.
userId:
type: string
format: uuid
description: The user id.
example: '442321'
description: 'The topcoder user id'
projectId:
type: integer
description: The project id.
Expand Down Expand Up @@ -5779,8 +5778,8 @@ components:
description: "The resource booking id."
userId:
type: string
format: uuid
description: "The user id."
example: '442321'
description: "The topcoder user id."
handle:
type: string
example: "Tony"
Expand Down Expand Up @@ -6023,8 +6022,8 @@ components:
description: "The job candidate id."
userId:
type: string
format: uuid
description: "User id."
example: '44231'
description: "The topcoder user id."
resume:
type: string
format: url
Expand Down Expand Up @@ -6369,7 +6368,7 @@ components:
userId:
type: number
example: 40157055
description: the user id
description: 'The topcoder user id'
handle:
type: string
example: maxceemdev
Expand Down Expand Up @@ -6701,7 +6700,8 @@ components:
properties:
userId:
type: string
format: uuid
example: '442321'
description: 'The topcoder user id'
defaultAvailableTime:
type: array
items:
Expand Down
4 changes: 2 additions & 2 deletions scripts/demo-email-notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ async function resetNotificationRecords () {

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

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

// reset upcoming resource booking expiration records
localLogger.info('reset upcoming resource booking expiration records')
Expand Down
42 changes: 1 addition & 41 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,45 +469,6 @@ async function getProjects (currentUser, criteria = {}) {
}
}

/**
* Function to get users
* @param {String} userId the user UUID
* @returns the found user details
*/
async function getUserDetailsByUserUUID (userUUID) {
const token = await getM2MToken()
const res = await request
.get(`${config.TC_API}/users/${userUUID}?enrich=true`)
.set('Authorization', `Bearer ${token}`)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
localLogger.debug({
context: 'getUserById',
message: `response body: ${JSON.stringify(res.body)}`
})
const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName', 'externalProfiles'])

if (!_.isUndefined(user.externalProfiles) && !_.isEmpty(user.externalProfiles)) {
_.assign(user, { userId: _.toInteger(_.get(user.externalProfiles[0], 'externalId')) })
}

const handleQuery = `handleLower:${user.handle.toLowerCase()}`
const userIdQuery = `userId:${user.userId}`

const query = _.concat(handleQuery, userIdQuery).join(URI.encodeQuery(' OR ', 'utf8'))
try {
const searchResult = await searchUsersByQuery(query)
const found = _.find(searchResult, !_.isUndefined(user.handle)
? ['handle', user.handle] : ['userId', user.userId]) || {}

return found
} catch (err) {
const error = new Error(err.response.text)
error.status = err.status
throw error
}
}

/**
* Search users by query string.
* @param {String} query the query string
Expand Down Expand Up @@ -620,7 +581,7 @@ async function getProjectById (currentUser, id) {
* @returns the request result
*/
async function getTopcoderSkills (criteria) {
const token = await getM2MUbahnToken()
const token = await getM2MToken()
try {
const res = await request
.get(`${config.TC_API}/skills`)
Expand Down Expand Up @@ -1650,7 +1611,6 @@ module.exports = {
getEmailTemplatesForKey,
formatDate,
formatDateTimeEDT,
getUserDetailsByUserUUID,
runExclusiveCalendarConnectionHandler,
waitForUnlockCalendarConnectionHandler,
runExclusiveInterviewEventHandler,
Expand Down
3 changes: 1 addition & 2 deletions src/models/Interview.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ module.exports = (sequelize) => {
availableTime: nylasAvailableTimeSchema('availableTime'),
hostUserId: {
field: 'hostUserId',
type: Sequelize.UUID,
allowNull: false
type: Sequelize.TEXT
},
expireTimestamp: {
field: 'expireTimestamp',
Expand Down
12 changes: 6 additions & 6 deletions src/services/InterviewService.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ async function requestInterview (currentUser, jobCandidateId, interview) {

// if M2M require hostUserId
if (currentUser.isMachine) {
const hostUserIdValidator = Joi.string().uuid().required()
const hostUserIdValidator = Joi.string().required()
const { error } = hostUserIdValidator.validate(interview.hostUserId)
if (error) {
throw new errors.BadRequestError(`interview.hostUserId ${interview.hostUserId} is required and must be a valid uuid`)
throw new errors.BadRequestError(`interview.hostUserId ${interview.hostUserId} is required and must be a valid topcoder user id`)
}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ async function requestInterview (currentUser, jobCandidateId, interview) {
// get calendar if exists, otherwise create a virtual one for the user
const existentCalendar = await UserMeetingSettings.getPrimaryNylasCalendarForUser(interview.hostUserId)
if (_.isNil(existentCalendar)) {
const { email, firstName, lastName } = await helper.getUserDetailsByUserUUID(interview.hostUserId)
const { email, firstName, lastName } = await helper.ensureTopcoderUserIdExists(interview.hostUserId)
const currentUserFullname = `${firstName} ${lastName}`
calendar = await createVirtualCalendarForUser(interview.hostUserId, email, currentUserFullname, interview.hostTimezone)
// make the new calendar primary
Expand Down Expand Up @@ -290,7 +290,7 @@ requestInterview.schema = Joi.object().keys({
interview: Joi.object().keys({
duration: Joi.number().integer().positive().required(),
hostTimezone: Joi.string().required(),
hostUserId: Joi.string().uuid(),
hostUserId: Joi.string(),
expireTimestamp: Joi.date(),
availableTime: Joi.array().min(1).items(
Joi.object({
Expand Down Expand Up @@ -400,7 +400,7 @@ partiallyUpdateInterviewByRound.schema = Joi.object().keys({
data: Joi.object().keys({
duration: Joi.number().integer().positive(),
hostTimezone: Joi.string(),
hostUserId: Joi.string().uuid(),
hostUserId: Joi.string(),
expireTimestamp: Joi.date(),
availableTime: Joi.array().min(1).items(
Joi.object({
Expand Down Expand Up @@ -448,7 +448,7 @@ partiallyUpdateInterviewById.schema = Joi.object().keys({
data: Joi.object().keys({
duration: Joi.number().integer().positive(),
hostTimezone: Joi.string(),
hostUserId: Joi.string().uuid(),
hostUserId: Joi.string(),
expireTimestamp: Joi.date(),
availableTime: Joi.array().min(1).items(
Joi.object({
Expand Down
4 changes: 2 additions & 2 deletions src/services/NotificationsSchedulerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ async function getDataForInterview (interview, jobCandidate, job) {

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

const hostUserDetails = await helper.getUserDetailsByUserUUID(interview.hostUserId)
const userDetails = await helper.getUserDetailsByUserUUID(jobCandidate.userId)
const hostUserDetails = await helper.ensureTopcoderUserIdExists(interview.hostUserId)
const userDetails = await helper.ensureTopcoderUserIdExists(jobCandidate.userId)
let tcUser
try {
tcUser = await helper.ensureTopcoderUserIdExists(jobCandidate.userId)
Expand Down
2 changes: 1 addition & 1 deletion src/services/NylasWebhookService.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async function processCalendarCreatedWebhook (webhookData, webhookId) {

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

await UserMeetingSettingsService.syncUserMeetingsSettings(user, {
id: userMeetingSettingsForCalendar.id,
Expand Down
2 changes: 1 addition & 1 deletion src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ async function getTeamJob (currentUser, id, jobId) {
})

// request host user details only one time if all interview are hosted by the same host
const hostUserDetails = await Promise.all(_.map(_.keys(hostMap), hostId => helper.getUserDetailsByUserUUID(hostId)))
const hostUserDetails = await Promise.all(_.map(_.keys(hostMap), hostId => helper.ensureTopcoderUserIdExists(hostId)))
_.map(_.keys(hostMap), (hostId, index) => {
hostMap[hostId] = hostUserDetails[index]
})
Expand Down
2 changes: 1 addition & 1 deletion src/services/UserMeetingSettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async function handleConnectCalendarCallback (reqQuery) {
// as a current user use the user who is connecting the calendar
// NOTE, that we cannot use `userId` because it's UUID, while in
// `currentUser` we need to have integer user id
const currentUser = _.pick(await helper.getUserDetailsByUserUUID(userId), ['userId', 'handle'])
const currentUser = _.pick(await helper.ensureTopcoderUserIdExists(userId), ['userId', 'handle'])

await syncUserMeetingsSettings(
currentUser,
Expand Down

0 comments on commit ad305a3

Please sign in to comment.