Added Properties to Vegetable
This commit is contained in:
parent
c9652c1366
commit
6d94b5f60c
9 changed files with 277 additions and 1 deletions
75
routes/properties.js
Normal file
75
routes/properties.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const Properties = require('../middleware/Properties')
|
||||
|
||||
module.exports = function (passport) {
|
||||
const basePath = '/api/properties/'
|
||||
const itemPath = basePath + ':propertyId'
|
||||
|
||||
router.route(basePath)
|
||||
.get(
|
||||
function (req, res) {
|
||||
Properties.getAll(req, function (err, items) {
|
||||
if (err) {
|
||||
res.status(items || 500).send(err.message)
|
||||
} else {
|
||||
res.status(200).json(items)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
.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)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
router.route(itemPath)
|
||||
.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