Created
May 31, 2019 01:14
-
-
Save jcharles22/f2ec514a196e5d628781b2710756b411 to your computer and use it in GitHub Desktop.
Working with the Express response object Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
//data to import | |
const playstore = require('./playstore'); | |
const app = express(); | |
app.get('/apps', (req, res, next) => { | |
let { sort, genres='' } = req.query | |
if(sort) { | |
if(!['rating', 'app'].includes(sort.toLowerCase())) { | |
res.status(400).send('Sort has to be rating or app.') | |
} | |
} | |
if(genres) { | |
if(!['action', 'puzzle', 'strategy', 'casual', 'arcade', 'card'].includes(genres.toLowerCase())) { | |
res.status(400).send('Genre has to be Action, Puzzle, Strategy, Casual, Arcade, or Card .') | |
} | |
} | |
let results = playstore.filter(game => | |
game.Genres.toLowerCase().includes(genres.toLowerCase())); | |
if(sort) { | |
results.sort((a,b) => { | |
return a[sort] > b[sort] ? 1 : a[sort] < b[sort] ? -1 : 0; | |
}); | |
} | |
res.send(results); | |
}) | |
app.listen(8000, () => { | |
console.log('Server started on PORT 8000'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment