- Removed test data from db files, cleaned structures, and fix other things

This commit is contained in:
Alexis
2020-06-22 21:36:51 +02:00
parent 49bddf0939
commit 96d13ec6e9
15 changed files with 186 additions and 227 deletions

View File

@@ -6,17 +6,12 @@ let router = express.Router()
// Connection
const connection = require('../database/bookshelf')
const db = connection.db
const functions = require('../functions')
// Repository
const VariableRepository = require('../repositories/variable-repository');
const Variables = new VariableRepository();
const regexInt = RegExp(/^[1-9]\d*$/)
// Error handling
const { HttpError } = require('../validations/Errors')
// ROUTES
// GET ALL ------------------
const getvariables = () => {
@@ -167,24 +162,7 @@ router.delete('/:id/', async (req, res) => {
})
})
// Param validation for ID
// (check if id is int) (could be refactored)
router.param('id', (req, res, next, id) => {
try {
if (regexInt.test(id)) {
next()
} else {
throw new Error;
}
} catch (err) {
err = new HttpError(403, 'Provided ID must be an integer and not zero')
res.status(err.code).send(JSON.stringify(
{
"error": err.message,
"code": err.code
})
)
}
})
// Param validations
router.param('id', functions.paramIntCheck)
module.exports = router