@@ -8,7 +8,7 @@ const config = require('config')
8
8
const HttpStatus = require ( 'http-status-codes' )
9
9
const { Op } = require ( 'sequelize' )
10
10
const { v4 : uuid } = require ( 'uuid' )
11
- const { Scopes, TopCoderUserPermissionRole } = require ( '../../app-constants' )
11
+ const { Scopes, UserRoles } = require ( '../../app-constants' )
12
12
const helper = require ( '../common/helper' )
13
13
const logger = require ( '../common/logger' )
14
14
const errors = require ( '../common/errors' )
@@ -365,35 +365,40 @@ searchJobCandidates.schema = Joi.object().keys({
365
365
* @params {Object} currentUser the user who perform this operation
366
366
* @params {String} id the jobCandidate id
367
367
*/
368
- async function downlaodJobCandidateResume ( currentUser , id ) {
368
+ async function downloadJobCandidateResume ( currentUser , id ) {
369
369
const jobCandidate = await JobCandidate . findById ( id )
370
370
const { id : currentUserUserId } = await helper . getUserByExternalId ( currentUser . userId )
371
371
372
372
// 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
+ }
386
389
}
387
- }
388
- } )
390
+ } )
389
391
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
+ }
391
396
}
392
397
393
- return helper . downloadResume ( jobCandidate . resume )
398
+ return jobCandidate . resume
394
399
}
395
400
396
- downlaodJobCandidateResume . schema = Joi . object ( ) . keys ( {
401
+ downloadJobCandidateResume . schema = Joi . object ( ) . keys ( {
397
402
currentUser : Joi . object ( ) . required ( ) ,
398
403
id : Joi . string ( ) . uuid ( ) . required ( )
399
404
} ) . required ( )
@@ -405,5 +410,5 @@ module.exports = {
405
410
fullyUpdateJobCandidate,
406
411
deleteJobCandidate,
407
412
searchJobCandidates,
408
- downlaodJobCandidateResume
413
+ downloadJobCandidateResume
409
414
}
0 commit comments