Created
June 1, 2019 21:31
-
-
Save jcharles22/fbe251280bb489ea13e86d69e6abb2a3 to your computer and use it in GitHub Desktop.
Integration Testing 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'); | |
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); | |
}) | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment