Log the output response (with your logging included) and you’ll see:
{ _id: '12', from: undefined, to: undefined, limit: undefined }
{
username: 'fcc_test_16434159457',
count: 2,
_id: '12',
log: [
{ description: 'test', duration: 60, date: 'Mon Jan 01 1990' },
{ description: 'test', duration: 60, date: 'Tue Jan 02 1990' }
]
}
{ _id: '12', from: undefined, to: undefined, limit: undefined }
{
username: 'fcc_test_16434159457',
count: 2,
_id: '12',
log: [
{ description: 'test', duration: 60, date: 'Mon Jan 01 1990' },
{ description: 'test', duration: 60, date: 'Tue Jan 02 1990' }
]
}
So, there is no filtering. It’s because the route doesn’t know the filter parameters:
{ _id: '12', from: undefined, to: undefined, limit: undefined }
The spec here could be clearer:
You can add from
, to
and limit
parameters to a GET /api/users/:_id/logs
request to retrieve part of the log of any user.
Since those parameters are not included in the enpoint, they are query parameters and not route parameters. Logging the input:
req.body: {}
req.params: {"_id":"12"}
req.query: {"from":"1989-12-31","to":"1990-01-03"}
Your endpoint
app.get('/api/users/:_id/logs/:from?/:to?/:limit?', (req, res) => {
is looking in req.params
for route parameters.