Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. // Import express and create a router
  2. let Express = require('express')
  3. const router = new Express.Router()
  4.  
  5. // Import the raw board game data
  6. const GameData = require('./games')
  7.  
  8. // Data enpoint for ALL Games
  9. router.get('/allGames', (req, res) => {
  10. let GamesReduced = summaryOnly(GameData)
  11. res.send(GamesReduced)
  12. console.log('/allGames endpoint reached')
  13. })
  14.  
  15. // Data endpoint for a single Game
  16. router.get('/Game/:id', (req, res) => {
  17.  
  18. let element = GameData.find(function (element) {
  19. return element.id === req.params.id;
  20. })
  21. res.send(element);
  22. console.log('/Game endpont reached')
  23. })
  24.  
  25. // Exposes router to be imported elsewhere
  26. exports.router = router
  27.  
  28. // Build and return a summary only version of GameData
  29. function summaryOnly (data) {
  30. // Remap data to a reduced form
  31. let mappedData = data.map((Game) => {
  32. // Build and return a Game summary
  33. let GameSummary = {
  34. id: Game.id,
  35. name: Game.name,
  36. year: Game.year,
  37. genre: Game.bgg_rating
  38. }
  39. return GameSummary
  40. })
  41.  
  42. // Return the summary array
  43. return mappedData
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement