- Removed test data from db files, cleaned structures, and fix other things
This commit is contained in:
@@ -10,7 +10,8 @@ const IngredientValidation = require("../validations/IngredientValidation")
|
||||
v.addSchema(IngredientValidation, "/IngredientValidation")
|
||||
|
||||
// Validations
|
||||
const regexXSS = RegExp(/<[^>]*script/)
|
||||
const isXSSAttempt = require('../functions').isXSSAttempt
|
||||
const isEmptyObject = require('../functions').isEmptyObject
|
||||
|
||||
// Error handling
|
||||
const { HttpError } = require('../validations/Errors')
|
||||
@@ -68,11 +69,11 @@ class IngredientRepository {
|
||||
addOne(igr) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
||||
if (this.isEmptyObject(igr)) {
|
||||
if (isEmptyObject(igr)) {
|
||||
reject(new HttpError(403, "Error: Ingredient cannot be nothing !"))
|
||||
} else if (!v.validate(igr, IngredientValidation).valid) {
|
||||
reject(new HttpError(403, "Error: Schema is not valid - " + v.validate(igr, IngredientValidation).errors))
|
||||
} else if (this.isXSSAttempt(igr.description)) {
|
||||
} else if (isXSSAttempt(igr.description)) {
|
||||
reject(new HttpError(403, 'Injection attempt detected, aborting the request.'))
|
||||
} else {
|
||||
bookshelf.transaction(t => {
|
||||
@@ -103,11 +104,11 @@ class IngredientRepository {
|
||||
updateOne(id, igr) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
||||
if (this.isEmptyObject(igr)) {
|
||||
if (isEmptyObject(igr)) {
|
||||
reject(new HttpError(403, "Error: Ingredient cannot be nothing !"))
|
||||
} else if (!v.validate(igr, IngredientValidation).valid) {
|
||||
reject(new HttpError(403, "Error: Schema is not valid - " + v.validate(igr, IngredientValidation).errors))
|
||||
} else if (this.isXSSAttempt(igr.description)) {
|
||||
} else if (isXSSAttempt(igr.description)) {
|
||||
reject(new HttpError(403, 'Injection attempt detected, aborting the request.'))
|
||||
} else {
|
||||
model.forge({id: id})
|
||||
@@ -165,24 +166,6 @@ class IngredientRepository {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Check if object is null
|
||||
isEmptyObject(obj) {
|
||||
if (Object.keys(obj).length === 0 && obj.constructor === Object) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check if script injection attempt
|
||||
isXSSAttempt(string) {
|
||||
if (regexXSS.test(string)) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = IngredientRepository
|
||||
Reference in New Issue
Block a user