Skip to content

Commit ad4c66a

Browse files
committed
fix: issue #475
1 parent 198d276 commit ad4c66a

File tree

5 files changed

+31
-42
lines changed

5 files changed

+31
-42
lines changed

app-constants.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const UserRoles = {
99
TopcoderUser: 'Topcoder User'
1010
}
1111

12-
const TopCoderUserPermissionRole = UserRoles.TopcoderUser
13-
1412
const FullManagePermissionRoles = [
1513
UserRoles.BookingManager,
1614
UserRoles.Administrator
@@ -165,7 +163,6 @@ const JobCandidateStatus = {
165163

166164
module.exports = {
167165
UserRoles,
168-
TopCoderUserPermissionRole,
169166
FullManagePermissionRoles,
170167
Scopes,
171168
Interviews,

src/common/helper.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,15 +1073,6 @@ async function getTopcoderUserById (userId) {
10731073
return user
10741074
}
10751075

1076-
/**
1077-
* Function to download resume
1078-
* @param {String} resumeUrl the resume id
1079-
* @returns the request result
1080-
*/
1081-
async function downloadResume (resumeUrl) {
1082-
return request.get(resumeUrl)
1083-
}
1084-
10851076
/**
10861077
* Function to get users
10871078
* @param {String} userId the user id
@@ -2073,7 +2064,6 @@ module.exports = {
20732064
}
20742065
return ensureUbahnUserId({ userId })
20752066
},
2076-
downloadResume,
20772067
getUserByExternalId,
20782068
getM2MToken,
20792069
getM2MUbahnToken,

src/controllers/JobCandidateController.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ async function searchJobCandidates (req, res) {
6969
* @param req the request
7070
* @param res the response
7171
*/
72-
async function downlaodJobCandidateResume (req, res) {
73-
const { body, res: { headers } } = await service.downlaodJobCandidateResume(req.authUser, req.params.id)
74-
for (const h in headers) {
75-
res.setHeader(h, headers[h])
76-
}
77-
res.send(body)
72+
async function downloadJobCandidateResume (req, res) {
73+
const resumeUrl = await service.downloadJobCandidateResume(req.authUser, req.params.id)
74+
res.redirect(resumeUrl)
7875
}
7976

8077
module.exports = {
@@ -84,5 +81,5 @@ module.exports = {
8481
fullyUpdateJobCandidate,
8582
deleteJobCandidate,
8683
searchJobCandidates,
87-
downlaodJobCandidateResume
84+
downloadJobCandidateResume
8885
}

src/routes/JobCandidateRoutes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747
'/jobCandidates/:id/resume': {
4848
get: {
4949
controller: 'JobCandidateController',
50-
method: 'downlaodJobCandidateResume',
50+
method: 'downloadJobCandidateResume',
5151
auth: 'jwt',
5252
scopes: [constants.Scopes.READ_JOB_CANDIDATE, constants.Scopes.ALL_JOB_CANDIDATE]
5353
}

src/services/JobCandidateService.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config = require('config')
88
const HttpStatus = require('http-status-codes')
99
const { Op } = require('sequelize')
1010
const { v4: uuid } = require('uuid')
11-
const { Scopes, TopCoderUserPermissionRole } = require('../../app-constants')
11+
const { Scopes, UserRoles } = require('../../app-constants')
1212
const helper = require('../common/helper')
1313
const logger = require('../common/logger')
1414
const errors = require('../common/errors')
@@ -365,35 +365,40 @@ searchJobCandidates.schema = Joi.object().keys({
365365
* @params {Object} currentUser the user who perform this operation
366366
* @params {String} id the jobCandidate id
367367
*/
368-
async function downlaodJobCandidateResume (currentUser, id) {
368+
async function downloadJobCandidateResume (currentUser, id) {
369369
const jobCandidate = await JobCandidate.findById(id)
370370
const { id: currentUserUserId } = await helper.getUserByExternalId(currentUser.userId)
371371

372372
// customer role
373-
if (!jobCandidate.viewedByCustomer && currentUserUserId !== jobCandidate.userId && currentUser.roles.length === 1 && currentUser.roles[0] === TopCoderUserPermissionRole) {
374-
const job = await models.Job.findById(jobCandidate.jobId)
375-
const { handle } = await helper.getUserById(jobCandidate.userId, true)
376-
const { email } = await helper.getMemberDetailsByHandle(handle)
377-
378-
await EmailNotificationService.sendEmail(currentUser, {
379-
template: 'taas.notification.job-candidate-resume-viewed',
380-
recipients: [email],
381-
data: {
382-
jobCandidateUserHandle: handle,
383-
jobName: job.title,
384-
notificationType: {
385-
jobCandidateResumeViewed: true
373+
if (!jobCandidate.viewedByCustomer && currentUserUserId !== jobCandidate.userId && currentUser.roles.length === 1 && currentUser.roles[0] === UserRoles.TopcoderUser) {
374+
try {
375+
const job = await models.Job.findById(jobCandidate.jobId)
376+
const { handle } = await helper.getUserById(jobCandidate.userId, true)
377+
const { email } = await helper.getMemberDetailsByHandle(handle)
378+
379+
await EmailNotificationService.sendEmail(currentUser, {
380+
template: 'taas.notification.job-candidate-resume-viewed',
381+
recipients: [email],
382+
data: {
383+
jobCandidateUserHandle: handle,
384+
jobName: job.title,
385+
description: 'Client Viewed Resume',
386+
notificationType: {
387+
jobCandidateResumeViewed: true
388+
}
386389
}
387-
}
388-
})
390+
})
389391

390-
await updateJobCandidate(currentUser, jobCandidate.id, { viewedByCustomer: true })
392+
await updateJobCandidate(currentUser, jobCandidate.id, { viewedByCustomer: true })
393+
} catch (err) {
394+
logger.logFullError(err, { component: 'JobCandidateService', context: 'downloadJobCandidateResume' })
395+
}
391396
}
392397

393-
return helper.downloadResume(jobCandidate.resume)
398+
return jobCandidate.resume
394399
}
395400

396-
downlaodJobCandidateResume.schema = Joi.object().keys({
401+
downloadJobCandidateResume.schema = Joi.object().keys({
397402
currentUser: Joi.object().required(),
398403
id: Joi.string().uuid().required()
399404
}).required()
@@ -405,5 +410,5 @@ module.exports = {
405410
fullyUpdateJobCandidate,
406411
deleteJobCandidate,
407412
searchJobCandidates,
408-
downlaodJobCandidateResume
413+
downloadJobCandidateResume
409414
}

0 commit comments

Comments
 (0)