Format and test fixes
This commit is contained in:
10
api/validation/commonSchemas.js
Normal file
10
api/validation/commonSchemas.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "email"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
}
|
||||
}
|
||||
16
api/validation/index.js
Normal file
16
api/validation/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const Ajv = require(`ajv`);
|
||||
|
||||
const { validationError } = require(`../utils`);
|
||||
|
||||
const validateOrThrow = (schema, data) => {
|
||||
const ajv = new Ajv();
|
||||
const valid = ajv.validate(schema, data);
|
||||
|
||||
if (!valid) {
|
||||
throw validationError(ajv.errors);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateOrThrow,
|
||||
};
|
||||
Reference in New Issue
Block a user