Authguard sub routes
This commit is contained in:
@@ -23,21 +23,23 @@ const getIngredients = () => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/', async (req, res) => {
|
router.get(
|
||||||
getIngredients()
|
'/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getIngredients()
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
@@ -48,21 +50,23 @@ const getIngredient = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/', async (req, res) => {
|
router.get(
|
||||||
getIngredient(req.params.id)
|
'/:id/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getIngredient(req.params.id)
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
@@ -73,21 +77,23 @@ const getSpellsFromOne = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/spells', async (req, res) => {
|
router.get(
|
||||||
getSpellsFromOne(req.params.id)
|
'/:id/spells',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getSpellsFromOne(req.params.id)
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
@@ -98,21 +104,24 @@ const addIngredient = (igr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.post('/', async (req, res) => {
|
router.post(
|
||||||
addIngredient(req.body)
|
'/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_INGREDIENTS']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
addIngredient(req.body)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
@@ -123,21 +132,24 @@ const updateIngredient = (id, igr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.put('/:id/', async (req, res) => {
|
router.put(
|
||||||
updateIngredient(req.params.id, req.body)
|
'/:id/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
updateIngredient(req.params.id, req.body)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
@@ -148,21 +160,24 @@ const deleteIngredient = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.delete('/:id/', async (req, res) => {
|
router.delete(
|
||||||
deleteIngredient(req.params.id)
|
'/:id/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS', 'DELETE_INGREDIENTS']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
deleteIngredient(req.params.id)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck)
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ const updateSchool = (id, s) => {
|
|||||||
}
|
}
|
||||||
router.put(
|
router.put(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
|
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
updateSchool(req.params.id, req.body)
|
updateSchool(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
@@ -160,6 +161,7 @@ const deleteSchool = (id) => {
|
|||||||
}
|
}
|
||||||
router.delete(
|
router.delete(
|
||||||
'/:id/',
|
'/:id/',
|
||||||
|
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS', 'DELETE_SCHOOLS']),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
deleteSchool(req.params.id)
|
deleteSchool(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
|
|||||||
@@ -23,21 +23,23 @@ const getvariables = () => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/', async (req, res) => {
|
router.get(
|
||||||
getvariables()
|
'/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getvariables()
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
@@ -48,21 +50,23 @@ const getVariable = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/', async (req, res) => {
|
router.get(
|
||||||
getVariable(req.params.id)
|
'/:id/',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getVariable(req.params.id)
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
@@ -73,21 +77,23 @@ const getSpellsFromOne = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/spells', async (req, res) => {
|
router.get(
|
||||||
getSpellsFromOne(req.params.id)
|
'/:id/spells',
|
||||||
.then(v => {
|
async (req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
getSpellsFromOne(req.params.id)
|
||||||
res.end(JSON.stringify(v))
|
.then(v => {
|
||||||
})
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
.catch(err => {
|
res.end(JSON.stringify(v))
|
||||||
res.status(err.code).send(JSON.stringify(
|
})
|
||||||
{
|
.catch(err => {
|
||||||
"error": err.message,
|
res.status(err.code).send(JSON.stringify(
|
||||||
"code": err.code
|
{
|
||||||
})
|
"error": err.message,
|
||||||
)
|
"code": err.code
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
@@ -98,21 +104,24 @@ const addVariable = (vr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.post('/', async (req, res) => {
|
router.post(
|
||||||
addVariable(req.body)
|
'/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_VARIABLES']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
addVariable(req.body)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
@@ -123,21 +132,24 @@ const updateVariable = (id, vr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.put('/:id/', async (req, res) => {
|
router.put(
|
||||||
updateVariable(req.params.id, req.body)
|
'/:id/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
updateVariable(req.params.id, req.body)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
@@ -148,21 +160,24 @@ const deleteVariable = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.delete('/:id/', async (req, res) => {
|
router.delete(
|
||||||
deleteVariable(req.params.id)
|
'/:id/',
|
||||||
.then(v => {
|
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES', 'DELETE_VARIABLES']),
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
async (req, res) => {
|
||||||
res.send(JSON.stringify(v))
|
deleteVariable(req.params.id)
|
||||||
})
|
.then(v => {
|
||||||
.catch(err => {
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
res.status(err.code).send(JSON.stringify(
|
res.send(JSON.stringify(v))
|
||||||
{
|
})
|
||||||
"error": err.message,
|
.catch(err => {
|
||||||
"code": err.code
|
res.status(err.code).send(JSON.stringify(
|
||||||
})
|
{
|
||||||
)
|
"error": err.message,
|
||||||
})
|
"code": err.code
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck)
|
||||||
|
|||||||
Reference in New Issue
Block a user