I am new to nodejs. I am creating an api for searching a particular data from the inputs – date from, dateto and id to display some data in a table – o/p – (username, datetime, id) with pagination
JSON data
{
[
{
"userId":"1",
"userName":"Jack",
"dateTime":"2021-08-02 03:13:29",
},
{
"userId":"3",
"userName":"John",
"dateTime":"2021-08-02 03:13:29",
}
],
"totalRecords": 2,
"numberOfRecords": 2,
"page": 1
}
Here is my code
let data= {
logs:require('./logs.json'),
}
app.get('/logs', (req, res) => {
if (req.headers.authorization) {
res.status(200);
res.send(JSON.stringify(logResponse(req.body));
} else {
res.status(401);
res.send();
}
});
const logResponse = (str) => {
console.log(str)
const logData = data.logs.filter((log) =>
log.logName.toLowerCase().includes(str.toLowerCase())
);
const bodyData = { logs: logData };
return { header: header(), body: bodyData };
};