Added Vegetable <-> Properties
This commit is contained in:
parent
6d94b5f60c
commit
abffdc9438
2 changed files with 169 additions and 0 deletions
|
@ -2,13 +2,17 @@ const express = require('express')
|
|||
const router = express.Router()
|
||||
const Vegetables = require('../middleware/Vegetables')
|
||||
const Pictures = require('../middleware/Pictures')
|
||||
const Properties = require('../middleware/VegetableProperties')
|
||||
|
||||
module.exports = function (passport) {
|
||||
const basePath = '/api/types/:vegetableTypesId/vegetables'
|
||||
const itemPath = basePath + '/:vegetablesId'
|
||||
const picturesPath = itemPath + '/pictures'
|
||||
const picturePath = picturesPath + '/:pictureId'
|
||||
const propertiesPath = itemPath + '/properties'
|
||||
const propertyPath = propertiesPath + '/:propertyId'
|
||||
|
||||
/* Vegetables */
|
||||
router.route(basePath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
|
@ -35,6 +39,7 @@ module.exports = function (passport) {
|
|||
}
|
||||
)
|
||||
|
||||
/* Vegetable */
|
||||
router.route(itemPath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
|
@ -74,6 +79,7 @@ module.exports = function (passport) {
|
|||
}
|
||||
)
|
||||
|
||||
/* Pictures */
|
||||
router.route(picturesPath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
|
@ -100,6 +106,7 @@ module.exports = function (passport) {
|
|||
}
|
||||
)
|
||||
|
||||
/* Picture */
|
||||
router.route(picturePath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
|
@ -126,5 +133,72 @@ module.exports = function (passport) {
|
|||
}
|
||||
)
|
||||
|
||||
/* Properties */
|
||||
router.route(propertiesPath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
Properties.getAll(req, function (err, item) {
|
||||
if (err) {
|
||||
res.status(item || 500).send(err.message)
|
||||
} else {
|
||||
res.status(200).json(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
.post(
|
||||
passport.authenticate(['basic-auth']),
|
||||
function (req, res) {
|
||||
const property = new Properties()
|
||||
property.createOne(req, function (err, item) {
|
||||
if (err) {
|
||||
res.status(item || 500).send(err.message)
|
||||
} else {
|
||||
res.status(201).json(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
/* Property */
|
||||
router.route(propertyPath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
Properties.getOne(req, function (err, item) {
|
||||
if (err) {
|
||||
res.status(item || 500).send(err.message)
|
||||
} else {
|
||||
res.status(200).json(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
.patch(
|
||||
passport.authenticate(['basic-auth']),
|
||||
function (req, res) {
|
||||
const property = new Properties()
|
||||
property.patchOne(req, function (err, item) {
|
||||
if (err) {
|
||||
res.status(item || 500).send(err.message)
|
||||
} else {
|
||||
res.status(200).json(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
.delete(
|
||||
passport.authenticate(['basic-auth']),
|
||||
function (req, res) {
|
||||
const property = new Properties()
|
||||
property.deleteOne(req, function (err, item) {
|
||||
if (err) {
|
||||
res.status(item || 500).send(err.message)
|
||||
} else {
|
||||
res.status(200).json(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
return router
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue