Authguard sub routes
This commit is contained in:
@@ -23,7 +23,9 @@ const getIngredients = () => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/', async (req, res) => {
|
router.get(
|
||||||
|
'/',
|
||||||
|
async (req, res) => {
|
||||||
getIngredients()
|
getIngredients()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -37,7 +39,7 @@ router.get('/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
@@ -48,7 +50,9 @@ const getIngredient = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/', async (req, res) => {
|
router.get(
|
||||||
|
'/:id/',
|
||||||
|
async (req, res) => {
|
||||||
getIngredient(req.params.id)
|
getIngredient(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -62,7 +66,7 @@ router.get('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
@@ -73,7 +77,9 @@ const getSpellsFromOne = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/spells', async (req, res) => {
|
router.get(
|
||||||
|
'/:id/spells',
|
||||||
|
async (req, res) => {
|
||||||
getSpellsFromOne(req.params.id)
|
getSpellsFromOne(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -87,7 +93,7 @@ router.get('/:id/spells', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
@@ -98,7 +104,10 @@ const addIngredient = (igr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.post('/', async (req, res) => {
|
router.post(
|
||||||
|
'/',
|
||||||
|
authGuard(['SUBMIT_INGREDIENTS']),
|
||||||
|
async (req, res) => {
|
||||||
addIngredient(req.body)
|
addIngredient(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -112,7 +121,7 @@ router.post('/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
@@ -123,7 +132,10 @@ const updateIngredient = (id, igr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.put('/:id/', async (req, res) => {
|
router.put(
|
||||||
|
'/:id/',
|
||||||
|
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS']),
|
||||||
|
async (req, res) => {
|
||||||
updateIngredient(req.params.id, req.body)
|
updateIngredient(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -137,7 +149,7 @@ router.put('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
@@ -148,7 +160,10 @@ const deleteIngredient = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.delete('/:id/', async (req, res) => {
|
router.delete(
|
||||||
|
'/:id/',
|
||||||
|
authGuard(['SUBMIT_INGREDIENTS', 'MODIFY_INGREDIENTS', 'DELETE_INGREDIENTS']),
|
||||||
|
async (req, res) => {
|
||||||
deleteIngredient(req.params.id)
|
deleteIngredient(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -162,7 +177,7 @@ router.delete('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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,7 +23,9 @@ const getvariables = () => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/', async (req, res) => {
|
router.get(
|
||||||
|
'/',
|
||||||
|
async (req, res) => {
|
||||||
getvariables()
|
getvariables()
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -37,7 +39,7 @@ router.get('/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET ONE ------------------
|
// GET ONE ------------------
|
||||||
@@ -48,7 +50,9 @@ const getVariable = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/', async (req, res) => {
|
router.get(
|
||||||
|
'/:id/',
|
||||||
|
async (req, res) => {
|
||||||
getVariable(req.params.id)
|
getVariable(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -62,7 +66,7 @@ router.get('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// GET SPELLS FROM ONE ------------------
|
// GET SPELLS FROM ONE ------------------
|
||||||
@@ -73,7 +77,9 @@ const getSpellsFromOne = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.get('/:id/spells', async (req, res) => {
|
router.get(
|
||||||
|
'/:id/spells',
|
||||||
|
async (req, res) => {
|
||||||
getSpellsFromOne(req.params.id)
|
getSpellsFromOne(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -87,7 +93,7 @@ router.get('/:id/spells', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
@@ -98,7 +104,10 @@ const addVariable = (vr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.post('/', async (req, res) => {
|
router.post(
|
||||||
|
'/',
|
||||||
|
authGuard(['SUBMIT_VARIABLES']),
|
||||||
|
async (req, res) => {
|
||||||
addVariable(req.body)
|
addVariable(req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -112,7 +121,7 @@ router.post('/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// UPDATE ONE ------------------
|
// UPDATE ONE ------------------
|
||||||
@@ -123,7 +132,10 @@ const updateVariable = (id, vr) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.put('/:id/', async (req, res) => {
|
router.put(
|
||||||
|
'/:id/',
|
||||||
|
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES']),
|
||||||
|
async (req, res) => {
|
||||||
updateVariable(req.params.id, req.body)
|
updateVariable(req.params.id, req.body)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -137,7 +149,7 @@ router.put('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// DELETE ONE ------------------
|
// DELETE ONE ------------------
|
||||||
@@ -148,7 +160,10 @@ const deleteVariable = (id) => {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
router.delete('/:id/', async (req, res) => {
|
router.delete(
|
||||||
|
'/:id/',
|
||||||
|
authGuard(['SUBMIT_VARIABLES', 'MODIFY_VARIABLES', 'DELETE_VARIABLES']),
|
||||||
|
async (req, res) => {
|
||||||
deleteVariable(req.params.id)
|
deleteVariable(req.params.id)
|
||||||
.then(v => {
|
.then(v => {
|
||||||
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
@@ -162,7 +177,7 @@ router.delete('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Param validations
|
// Param validations
|
||||||
router.param('id', functions.paramIntCheck)
|
router.param('id', functions.paramIntCheck)
|
||||||
|
|||||||
Reference in New Issue
Block a user