const router = module.exports = require('express-promise-router')() const parseJSON = require('body-parser').json() const db = require('../db') const ensureAdmin = require('./middleware/ensureAdmin') const validate = require('./middleware/validators') router.get('/', ensureAdmin, async (req, res) => { const config = await db.config.getLatestConfig() res.json(config) }) router.post('/address', ensureAdmin, parseJSON, validate.addressWithPhone, async (req, res) => { const {name, street1, street2, city, state, zip, country, phone} = req.body; // Create address, update order const address = await db.address.create(name, street1, street2, city, state, zip, country, phone) const config = await db.config.setShippingAddress(address.uuid, req.user.uuid) res.json(config) })