I want to have an api endpoint to get all tasks which have a startDate as Today

35 Views Asked by At

I'm going nuts, I don't know why this doesn't work and returns a 404 error, here is the code :

app.get('/tasks/today', (req, res) => {
    const today = new Date().toISOString().slice(0, 10);
    db.all('SELECT * FROM tasks WHERE startDate = ?', [today], (err, tasks) => {
        if (err) {
            console.error(err.message);
            res.status(500).json({ error: 'Internal Server Error' });
        } else {
            res.json(tasks);
        }
    });
});

Like the other endpoints (Get task by id works great), I expected this to work just fine

1

There are 1 best solutions below

0
Yassin Kerroumi On

I fixed the problem, the order of the endpoints caused the issue, after putting this endpoint before /tasks/:id it worked, I think the api treated /today as /:id and it returned nothing