Authguard sub routes

This commit is contained in:
Alexis
2021-01-19 22:59:55 +01:00
parent efb9195053
commit b5e6f73d01
3 changed files with 212 additions and 180 deletions

View File

@@ -23,7 +23,9 @@ const getIngredients = () => {
throw err
})
}
router.get('/', async (req, res) => {
router.get(
'/',
async (req, res) => {
getIngredients()
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -37,7 +39,7 @@ router.get('/', async (req, res) => {
})
)
})
})
})
// GET ONE ------------------
@@ -48,7 +50,9 @@ const getIngredient = (id) => {
throw err
})
}
router.get('/:id/', async (req, res) => {
router.get(
'/:id/',
async (req, res) => {
getIngredient(req.params.id)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -62,7 +66,7 @@ router.get('/:id/', async (req, res) => {
})
)
})
})
})
// GET SPELLS FROM ONE ------------------
@@ -73,7 +77,9 @@ const getSpellsFromOne = (id) => {
throw err
})
}
router.get('/:id/spells', async (req, res) => {
router.get(
'/:id/spells',
async (req, res) => {
getSpellsFromOne(req.params.id)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -87,7 +93,7 @@ router.get('/:id/spells', async (req, res) => {
})
)
})
})
})
// CREATE ONE ------------------
@@ -98,7 +104,10 @@ const addIngredient = (igr) => {
throw err
})
}
router.post('/', async (req, res) => {
router.post(
'/',
authGuard(['SUBMIT_INGREDIENTS']),
async (req, res) => {
addIngredient(req.body)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -112,7 +121,7 @@ router.post('/', async (req, res) => {
})
)
})
})
})
// UPDATE ONE ------------------
@@ -123,7 +132,10 @@ const updateIngredient = (id, igr) => {
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)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -137,7 +149,7 @@ router.put('/:id/', async (req, res) => {
})
)
})
})
})
// DELETE ONE ------------------
@@ -148,7 +160,10 @@ const deleteIngredient = (id) => {
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)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -162,7 +177,7 @@ router.delete('/:id/', async (req, res) => {
})
)
})
})
})
// Param validations
router.param('id', functions.paramIntCheck)

View File

@@ -133,6 +133,7 @@ const updateSchool = (id, s) => {
}
router.put(
'/:id/',
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS']),
async (req, res) => {
updateSchool(req.params.id, req.body)
.then(v => {
@@ -160,6 +161,7 @@ const deleteSchool = (id) => {
}
router.delete(
'/:id/',
authGuard(['SUBMIT_SCHOOLS', 'MODIFY_SCHOOLS', 'DELETE_SCHOOLS']),
async (req, res) => {
deleteSchool(req.params.id)
.then(v => {

View File

@@ -23,7 +23,9 @@ const getvariables = () => {
throw err
})
}
router.get('/', async (req, res) => {
router.get(
'/',
async (req, res) => {
getvariables()
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -37,7 +39,7 @@ router.get('/', async (req, res) => {
})
)
})
})
})
// GET ONE ------------------
@@ -48,7 +50,9 @@ const getVariable = (id) => {
throw err
})
}
router.get('/:id/', async (req, res) => {
router.get(
'/:id/',
async (req, res) => {
getVariable(req.params.id)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -62,7 +66,7 @@ router.get('/:id/', async (req, res) => {
})
)
})
})
})
// GET SPELLS FROM ONE ------------------
@@ -73,7 +77,9 @@ const getSpellsFromOne = (id) => {
throw err
})
}
router.get('/:id/spells', async (req, res) => {
router.get(
'/:id/spells',
async (req, res) => {
getSpellsFromOne(req.params.id)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -87,7 +93,7 @@ router.get('/:id/spells', async (req, res) => {
})
)
})
})
})
// CREATE ONE ------------------
@@ -98,7 +104,10 @@ const addVariable = (vr) => {
throw err
})
}
router.post('/', async (req, res) => {
router.post(
'/',
authGuard(['SUBMIT_VARIABLES']),
async (req, res) => {
addVariable(req.body)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -112,7 +121,7 @@ router.post('/', async (req, res) => {
})
)
})
})
})
// UPDATE ONE ------------------
@@ -123,7 +132,10 @@ const updateVariable = (id, vr) => {
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)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -137,7 +149,7 @@ router.put('/:id/', async (req, res) => {
})
)
})
})
})
// DELETE ONE ------------------
@@ -148,7 +160,10 @@ const deleteVariable = (id) => {
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)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
@@ -162,7 +177,7 @@ router.delete('/:id/', async (req, res) => {
})
)
})
})
})
// Param validations
router.param('id', functions.paramIntCheck)