|
|
|
@ -24,7 +24,7 @@ router.get('/', async (req, res) => {
|
|
|
|
|
res.json(items)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const newItemValidators = [
|
|
|
|
|
const itemValidators = [
|
|
|
|
|
validate.validUrlSlug('urlslug'),
|
|
|
|
|
validate.publishedBool,
|
|
|
|
|
validate.positiveInteger('price_cents'),
|
|
|
|
@ -33,7 +33,7 @@ const newItemValidators = [
|
|
|
|
|
validate.handleApiError
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
router.post('/', parseJSON, newItemValidators, async (req, res) => {
|
|
|
|
|
router.post('/', parseJSON, itemValidators, async (req, res) => {
|
|
|
|
|
const item = await db.item.create(
|
|
|
|
|
req.body.name,
|
|
|
|
|
req.body.urlslug,
|
|
|
|
@ -50,6 +50,19 @@ router.get('/by-slug/:slug', async (req, res) => {
|
|
|
|
|
res.json(item)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.post('/:uuid', parseJSON, itemValidators, async (req, res) => {
|
|
|
|
|
const item = await db.item.update(
|
|
|
|
|
req.params.uuid,
|
|
|
|
|
req.body.name,
|
|
|
|
|
req.body.urlslug,
|
|
|
|
|
req.body.description,
|
|
|
|
|
req.body.price_cents,
|
|
|
|
|
req.body.published
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
res.json(item)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.post('/:uuid/images', upload.single('image'), async (req, res) => {
|
|
|
|
|
// Handle either image upload body or JSON body
|
|
|
|
|
try {
|
|
|
|
|