@@ -515,6 +515,38 @@ module.exports = (db) => {
515515 return next ( error ) ;
516516 }
517517
518+ // Validate that the work date is not in the future
519+ // This prevents users from logging time for dates that haven't occurred yet
520+ const workDate = new Date ( req . body . date ) ;
521+ const currentDate = new Date ( ) ;
522+ const currentDateOnly = new Date (
523+ currentDate . getFullYear ( ) ,
524+ currentDate . getMonth ( ) ,
525+ currentDate . getDate ( ) ,
526+ ) ;
527+ const workDateOnly = new Date (
528+ workDate . getFullYear ( ) ,
529+ workDate . getMonth ( ) ,
530+ workDate . getDate ( ) ,
531+ ) ;
532+
533+ if ( workDateOnly > currentDateOnly ) {
534+ const error = new Error ( "Cannot log time for future dates" ) ;
535+ error . statusCode = 400 ;
536+ return next ( error ) ;
537+ }
538+
539+ // Validate that the work date is within the past 14 days (2 weeks)
540+ // This maintains the existing business rule about recent time logging
541+ const twoWeeksAgo = new Date ( currentDateOnly ) ;
542+ twoWeeksAgo . setDate ( twoWeeksAgo . getDate ( ) - 14 ) ;
543+
544+ if ( workDateOnly < twoWeeksAgo ) {
545+ const error = new Error ( "Cannot log time for dates older than 14 days" ) ;
546+ error . statusCode = 400 ;
547+ return next ( error ) ;
548+ }
549+
518550 let mock_id = req . user . mock ? req . user . mock . system_id : "" ;
519551
520552 const sql = `INSERT INTO time_log
@@ -2353,7 +2385,7 @@ module.exports = (db) => {
23532385 ( req , res , next ) => {
23542386 calculateActiveTimelines ( req . user )
23552387 . then ( ( timelines ) => {
2356- res . send ( timelines ) ;
2388+ res . json ( timelines ) ;
23572389 } )
23582390 . catch ( ( err ) => {
23592391 console . error ( err ) ;
@@ -2564,6 +2596,29 @@ module.exports = (db) => {
25642596 }
25652597 db . query ( getHtmlQuery , queryParams )
25662598 . then ( ( html ) => {
2599+ // Replace placeholder with actual server base URL
2600+ const serverBaseUrl =
2601+ process . env . NODE_ENV === "production"
2602+ ? process . env . PRODUCTION_SERVER_URL ||
2603+ process . env . BASE_URL ||
2604+ `${ req . protocol } ://${ req . get ( "host" ) } `
2605+ : `${ req . protocol } ://${ req . get ( "host" ) } ` ;
2606+
2607+ // Process HTML to replace placeholders
2608+ if ( Array . isArray ( html ) ) {
2609+ html = html . map ( ( item ) => {
2610+ if ( item . html ) {
2611+ item . html = item . html . replace (
2612+ / _ _ S E R V E R _ B A S E _ U R L _ _ / g,
2613+ serverBaseUrl ,
2614+ ) ;
2615+ }
2616+ return item ;
2617+ } ) ;
2618+ } else if ( html && html . html ) {
2619+ html . html = html . html . replace ( / _ _ S E R V E R _ B A S E _ U R L _ _ / g, serverBaseUrl ) ;
2620+ }
2621+
25672622 res . send ( html ) ;
25682623 } )
25692624 . catch ( ( err ) => {
@@ -3081,7 +3136,7 @@ module.exports = (db) => {
30813136 ( req , res , next ) => {
30823137 let getSponsorNotesQuery = `
30833138 SELECT sponsor_notes.*,
3084- users.fname, users.lname, users.email,
3139+ users.fname, users.lname, users.email, users.type,
30853140 (SELECT users.fname || ' ' || users.lname FROM users WHERE users.system_id = sponsor_notes.mock_id) AS mock_name
30863141 FROM sponsor_notes
30873142 JOIN users
@@ -4213,8 +4268,9 @@ module.exports = (db) => {
42134268 }
42144269
42154270 let getPeerEvalLogsQuery = `
4216- SELECT *
4271+ SELECT action_log.*, users.fname, users.lname, users.type
42174272 FROM action_log
4273+ LEFT JOIN users ON action_log.system_id = users.system_id
42184274 WHERE action_template IN (${ actionIds . join ( "," ) } )
42194275 ORDER BY submission_datetime DESC
42204276 ` ;
0 commit comments