Added authGuard function and its implementations
Also refactored small code mistakes.
This commit is contained in:
@@ -5,9 +5,9 @@ const model = require('../models/meta-school-model')
|
||||
|
||||
// Model validation
|
||||
const Validator = require('jsonschema').Validator
|
||||
const v = new Validator()
|
||||
const validator = new Validator()
|
||||
const MetaSchoolValidation = require("../validations/MetaSchoolValidation")
|
||||
v.addSchema(MetaSchoolValidation, "/MetaSchoolValidation")
|
||||
validator.addSchema(MetaSchoolValidation, "/MetaSchoolValidation")
|
||||
|
||||
// Validations
|
||||
const regexXSS = RegExp(/<[^>]*script/)
|
||||
@@ -20,35 +20,35 @@ class MetaSchoolRepository {
|
||||
getAll() {
|
||||
return new Promise((resolve, reject) => {
|
||||
new model()
|
||||
.fetchAll({ withRelated: ['schools'] })
|
||||
.then(v => {
|
||||
resolve(v.toJSON({ omitPivot: true }))
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
reject({
|
||||
"message": "Il n'existe aucune grande école disponible.",
|
||||
"code": 404,
|
||||
});
|
||||
})
|
||||
.fetchAll({ withRelated: ['schools'] })
|
||||
.then(v => {
|
||||
resolve(v.toJSON({ omitPivot: true }))
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
reject({
|
||||
"message": "Il n'existe aucune grande école disponible.",
|
||||
"code": 404,
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getOne(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
new model()
|
||||
.where({ 'id' : id })
|
||||
.fetch({ withRelated: ['schools']})
|
||||
.then(v => {
|
||||
resolve(v.toJSON({ omitPivot: true }))
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
reject({
|
||||
"message": "La grande école en question n'a pas pu être trouvée.",
|
||||
"code": 404,
|
||||
});
|
||||
})
|
||||
.where({ 'id': id })
|
||||
.fetch({ withRelated: ['schools'] })
|
||||
.then(v => {
|
||||
resolve(v.toJSON({ omitPivot: true }))
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
reject({
|
||||
"message": "La grande école en question n'a pas pu être trouvée.",
|
||||
"code": 404,
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user