I want to be able to return a result set of data and just change the formatting of the date field to something more readable leaving all the other data intact. I would prefer t
Both ways worked for me. I think for testing I will use the forEach()
until I need to duplicate it and then I will create the separate function.
This is what I ended up with.
let moment = require('moment');
// Get all the Tasks
function getAllTasks() {
return models.gantt_tasks.findAll()
.then(function(tasks) {
tasks.forEach( task => task.start_date = moment(task.start_date).format("YYYY-MM-DD"));
return tasks;
})
.catch(function(e) {
console.error(e);
return e;
});
}
router.get('/data', (req, res) =>
getAllTasks()
.then((tasks) => res.json({ data: tasks }))
)
I ended up needing the Moment library to convert my dates as Sequelize wasn't let me easily manipulate the dates.