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
792 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')
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)
})