I have a feathersjs API with a messages service
. I want to validate the message model with feathers-hooks-validate-joi
module.
Here is my messages-hooks.js
file:
const validate = require('feathers-hooks-validate-joi');
const schema = require('./messages.validator');
module.exports = {
before: {
create: [validate.form(schema)],
//others method fields
},
after: {...},
error: {...}
};
Here is my messages.validator.js
file:
const Joi = require('joi');
const schema = Joi.object().keys({
name: Joi.string().trim().min(2).required(),
text: Joi.string().trim().min(2).required()
});
module.exports = {schema};
When I try to post a message via curl:
curl 'http://localhost:3030/messages/' -H 'Content-Type: application/json' --data-binary '{ "name": "Hello", "text": "World" }'
I receive this error message:
{
"name": "BadRequest",
"message": "Invalid data",
"code": 400,
"className": "bad-request",
"data": {},
"errors": {
"name": "\"name\" is not allowed",
"text": "\"text\" is not allowed"
}
}
Am I missing something? Am I using the feathers hook correctly?