Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Import express and create a router
- let Express = require('express')
- const router = new Express.Router()
- // Import the raw board game data
- const GameData = require('./games')
- // Data enpoint for ALL Games
- router.get('/allGames', (req, res) => {
- let GamesReduced = summaryOnly(GameData)
- res.send(GamesReduced)
- console.log('/allGames endpoint reached')
- })
- // Data endpoint for a single Game
- router.get('/Game/:id', (req, res) => {
- let element = GameData.find(function (element) {
- return element.id === req.params.id;
- })
- res.send(element);
- console.log('/Game endpont reached')
- })
- // Exposes router to be imported elsewhere
- exports.router = router
- // Build and return a summary only version of GameData
- function summaryOnly (data) {
- // Remap data to a reduced form
- let mappedData = data.map((Game) => {
- // Build and return a Game summary
- let GameSummary = {
- id: Game.id,
- name: Game.name,
- year: Game.year,
- genre: Game.bgg_rating
- }
- return GameSummary
- })
- // Return the summary array
- return mappedData
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement