Skip to content

Commit

Permalink
SPF-87
Browse files Browse the repository at this point in the history
Add the search to the Backend
  • Loading branch information
fefifef committed Mar 31, 2022
1 parent f4b5e84 commit ac14774
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Backend/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const intradayroute = require('./intraday');
const monthlyroute = require('./monthly');
const weeklyroute = require('./weekly');
const quotedUSshares = require('./quotedUSshares');
const search = require('./search');

const appRouter = (app, fs, apiKey) => {
app.get('/', (req, res) => {
Expand All @@ -14,7 +15,7 @@ const appRouter = (app, fs, apiKey) => {
monthlyroute(app, fs, apiKey);
weeklyroute(app, fs, apiKey);
quotedUSshares(app,fs, apiKey);

search(app,fs);
};

module.exports = appRouter;
23 changes: 23 additions & 0 deletions Backend/routes/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const userRoutes = (app, fs) => {
// variables
const dataPath = './data/quotedUSshares.json';

// READ
app.get('/search', (req, res) => {
if(req.query.text){
const searchText = req.query.text;
const rawData = fs.readFileSync(dataPath);
let result = JSON.parse(rawData);
let arrFound = result.filter(function(item) {
let isPartOf = item.symbol.includes(searchText) || item.name.includes(searchText);
return isPartOf;
});

res.send(arrFound);
return;
}
res.send("NO search Text");
});
};

module.exports = userRoutes;

0 comments on commit ac14774

Please sign in to comment.