18 lines
472 B
JavaScript
18 lines
472 B
JavaScript
const express = require('express')
|
|
const { listGames, getGameDetail } = require('../db')
|
|
|
|
const router = express.Router()
|
|
|
|
router.get('/', async (req, res) => {
|
|
const games = await listGames()
|
|
res.json({ games })
|
|
})
|
|
|
|
router.get('/:gameId', async (req, res) => {
|
|
const detail = await getGameDetail(req.params.gameId)
|
|
if (!detail) return res.status(404).json({ error: 'not_found' })
|
|
res.json({ game: detail.game, items: detail.items })
|
|
})
|
|
|
|
module.exports = router
|