I have this Express route:
app.use('/stop_jobs', function (req, res, next) {
const jobId = req.query && req.query.job_id;
const stopped : Array<any> = [];
for (let j of runningJobs.keys()) {
if(j.id === jobId){
stopped.push(j.stopThisInstance());
}
}
res.json({success: {stopped}});
});
where
const runningJobs = new Map<CDTChronBase,CDTChronBase>();
(CDTChronBase is a class)
the above works, but I'd like to simplify it if possible, something like this:
app.use('/stop_jobs', function (req, res, next) {
const jobId = req.query && req.query.job_id;
const stopped = runningJobs.keys().filter(j => {
return j.id === jobId;
})
.map(v => {
return j.stopThisInstance()
});
res.json({success: {stopped}});
});
but for the life of me, I cannot figure out how to get an Array instance of any of the methods on Map. Is there a way to use map/filter type methods on Map objects?