S
S
Stanislav2016-03-18 04:37:32
Node.js
Stanislav, 2016-03-18 04:37:32

How to fill an object field in npm Joi if it is missing?

I couldn't find an answer to my question in the documentation.
In general, I accept data from the form, and some fields may be empty, Joi in the case of an empty field starts to swear at him.
For example, there is such data to check

var data= {
    "price": ''
};

// Пишу схему для проверки
var schema = Joi.object().keys({
    "price": Joi.number().min(0).max(10)
});

Is it possible to somehow set the value of the key in the schema by default if the key is empty or does not pass validation?
And now you have to use extend and write the default values ​​of the keys, and the list of them is much larger. In addition, you also have to convert some fields into numbers, as a result, after all that has been done, Joi makes no sense.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Ulanov, 2016-03-18
@antonsr98

I have those that are not required to be filled with Joi.string ()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question