@@ -17,9 +17,6 @@ const userSkillsProfileController = function (UserProfile) {
1717 * Returns consistent structure regardless of data availability
1818 */
1919 const getUserSkillsProfile = async ( req , res , next ) => {
20- console . log ( 'req.body.requestor' ) ;
21- console . log ( req . body . requestor ) ;
22-
2320 try {
2421 // Check if user has permission to view user profiles
2522 const hasAccess = await hasPermission ( req . body . requestor , 'getUserProfiles' ) ;
@@ -86,7 +83,9 @@ const userSkillsProfileController = function (UserProfile) {
8683
8784 // Get skills data - use default values if not found
8885 const userIdObj = mongoose . Types . ObjectId ( userId ) ;
89- const formResponses = await HgnFormResponses . findOne ( { user_id : userIdObj } )
86+ const formResponses = await HgnFormResponses . findOne ( {
87+ $or : [ { user_id : userIdObj } , { user_id : userId } ] ,
88+ } )
9089 . sort ( { _id : - 1 } )
9190 . lean ( ) ;
9291 // Flag if we're using real or placeholder data
@@ -224,12 +223,6 @@ const userSkillsProfileController = function (UserProfile) {
224223 }
225224 //
226225 const updateUserSkillsProfileFollowUp = async ( req , res , next ) => {
227- console . log ( 'updateUserSkillsProfileFollowUp' ) ;
228-
229- console . log ( 'req.body.requestor' ) ;
230- console . log ( req . body ) ;
231-
232- console . log ( req . params ?. userId ) ;
233226 try {
234227 // Check if user has permission to view user profiles
235228 const hasAccess = await hasPermission ( req . body . requestor , 'updateUserSkillsProfileFollowUp' ) ;
@@ -315,8 +308,6 @@ const userSkillsProfileController = function (UserProfile) {
315308
316309 return res . status ( 200 ) . json ( { data : formResponsesUpd } ) ;
317310 } catch ( error ) {
318- console . log ( 'error' ) ;
319- console . log ( error ) ;
320311 // Log exceptions with transaction name and relevant data
321312 Logger . logException ( error , 'updateUserSkillsProfileFollowUp' , {
322313 requestorId : req . body . requestor ?. requestorId ,
@@ -326,11 +317,54 @@ const userSkillsProfileController = function (UserProfile) {
326317 next ( error ) ;
327318 }
328319 } ;
320+ const updateYearsOfExperience = async ( req , res , next ) => {
321+ try {
322+ const hasAccess =
323+ req . body . requestor . requestorId === req . params . userId ||
324+ ( await hasPermission ( req . body . requestor , 'updateUserSkillsProfileFollowUp' ) ) ;
325+ if ( ! hasAccess ) {
326+ return res . status ( 403 ) . json ( { error : 'You do not have permission to update this profile' } ) ;
327+ }
328+
329+ const { userId } = req . params ;
330+
331+ if ( ! mongoose . Types . ObjectId . isValid ( userId ) ) {
332+ throw new ValidationError ( 'Invalid user ID format' ) ;
333+ }
334+
335+ const { yearsOfExperience } = req . body ;
336+
337+ if ( yearsOfExperience !== '' && yearsOfExperience != null ) {
338+ const num = Number ( yearsOfExperience ) ;
339+ if ( ! Number . isInteger ( num ) || num < 0 ) {
340+ return res
341+ . status ( 400 )
342+ . json ( { error : 'Years of Experience must be a non-negative whole number' } ) ;
343+ }
344+ }
345+
346+ const updatedResponse = await HgnFormResponses . findOneAndUpdate (
347+ { user_id : mongoose . Types . ObjectId ( userId ) } ,
348+ { 'general.yearsOfExperience' : yearsOfExperience } ,
349+ { new : true , sort : { _id : - 1 } , upsert : true } ,
350+ ) ;
351+
352+ return res . status ( 200 ) . json ( { data : updatedResponse } ) ;
353+ } catch ( error ) {
354+ Logger . logException ( error , 'updateYearsOfExperience' , {
355+ requestorId : req . body . requestor ?. requestorId ,
356+ targetUserId : req . params ?. userId ,
357+ timestamp : new Date ( ) . toISOString ( ) ,
358+ } ) ;
359+ next ( error ) ;
360+ }
361+ } ;
329362
330363 //
331364 return {
332365 getUserSkillsProfile,
333366 updateUserSkillsProfileFollowUp,
367+ updateYearsOfExperience,
334368 } ;
335369} ;
336370
0 commit comments