You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
649 B
JavaScript

const router = module.exports = require('express-promise-router')()
const parseJSON = require('body-parser').json()
const db = require('../db')
const ensureAdmin = require('./middleware/ensureAdmin')
router.get('/', ensureAdmin, async (req, res) => {
const shipments = await db.shipment.findAll()
res.json(shipments)
})
router.get('/:uuid', ensureAdmin, async (req, res) => {
const shipment = await db.shipment.findByUUID(req.params.uuid)
res.json(shipment)
})
router.post('/', ensureAdmin, parseJSON, async (req, res) => {
const shipment = await db.shipment.createShipment(req.body.description, req.body.items)
res.json(shipment)
})