Add conver-time function to change time formatting and appearance. For exaple "FINISHED" now appears as "FT"

This commit is contained in:
Lucas Patenaude
2024-04-04 22:16:16 -06:00
parent a9f02ef97f
commit 3983d00caf
3 changed files with 31 additions and 0 deletions

View File

@@ -85,6 +85,10 @@ app.use(express.static(path.join(__dirname, 'resources')));
const fetchMatchesData = require('./resources/js/scoreboard-header/current-match-routes');
app.use(fetchMatchesData);
const convert_time = require('./resources/js/scoreboard-header/convert-time');
app.use(convert_time);
/************************
Login Page Routes
*************************/

View File

@@ -0,0 +1,27 @@
// Convert finished matches to "FT"
const convert_time = (req, res, next) => {
try {
// Access matches data from res.locals
const matches = res.locals.matches;
// Loop through matches and convert "FINISHED" to "FT" for minute
const convertedMatches = matches.map(match => {
if (match.minute === "FINISHED") {
match.minute = "FT";
}
return match;
});
// Update res.locals with converted matches
res.locals.matches = convertedMatches;
// Proceed to the next middleware/route handler
next();
} catch (error) {
// If an error occurs, log it and proceed to the next middleware/route handler
console.error('Error converting finished matches:', error);
next();
}
};
module.exports = convert_time;