diff --git a/Backend/routes/routes.js b/Backend/routes/routes.js index 702cdd82..1ac7cee2 100644 --- a/Backend/routes/routes.js +++ b/Backend/routes/routes.js @@ -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) => { @@ -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; \ No newline at end of file diff --git a/Backend/routes/search.js b/Backend/routes/search.js new file mode 100644 index 00000000..af9bfc5e --- /dev/null +++ b/Backend/routes/search.js @@ -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;