Refactor with base actions methods
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const Ajv = require(`ajv`);
|
||||
/*
|
||||
* Validation
|
||||
*/
|
||||
|
||||
const { validationError } = require(`../utils`);
|
||||
const Ajv = require(`ajv`);
|
||||
|
||||
const validateOrThrow = (schema, data) => {
|
||||
const ajv = new Ajv();
|
||||
@@ -11,6 +13,17 @@ const validateOrThrow = (schema, data) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a custom validation error
|
||||
* @param {array[string]} validationErrors Validation errors
|
||||
*/
|
||||
const validationError = (validationErrors = []) => {
|
||||
let error = new Error("Validation error(s)");
|
||||
error.validationErrors = validationErrors;
|
||||
error.code = 400;
|
||||
return error;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateOrThrow,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user