Seeking assistance with filtering data by date range and forwarding the results to the client. The objective is to extract tickets created within specific dates, but I keep encountering a console error which is proving challenging to resolve.
var before:Date = req.query.before;
if(before !== undefined){
//@ts-ignore
var after:Date = req.query.before;
var filteredData = tempData.filter(function(t){
return res.send(new Date(t.creationTime) >= after && new Date(t.creationTime) <= before);
});
}
This is the error message displayed in the console:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:558:11)
at ServerResponse.header (C:\Project\server\node_modules\express\lib\response.js:771:10)
at ServerResponse.json (C:\Project\server\node_modules\express\lib\response.js:264:10)
at ServerResponse.send (C:\Project\server\node_modules\express\lib\response.js:158:21)
at C:\Project\server\index.ts:48:20
at Array.filter (<anonymous>)
at C:\Project\server\index.ts:47:37
at Layer.handle [as handle_request] (C:\Project\server\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Project\server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Project\server\node_modules\express\lib\router\route.js:112:3)