Closed guillecro closed 6 years ago
We will be using ajv
cause i find it pretty interesting, and also I created a service to validate not only JSON schemas structures, but also data according to a JSON Schema. This will be like a interface for djv. If the schema is invalid, or if the data is invalid, then it will throw -our- errors. I created 2 types of errors:
const ErrInvalidJSONSchema = new APIError('JSON Schema is not valid. Probably because of bad format', {
translationKey: 'INVALID_JSON_SCHEMA',
status: BAD_REQUEST
})
const ErrInvalidData = new APIError('Data doesn\'t follow the specified JSON Schema.', {
translationKey: 'INVALID_DATA_FOR_JSON_SCHEMA',
status: BAD_REQUEST
}
The validation will be happening before saving the data in the database. So it will be under the saving methods for the db-api. Mongoose will handle the data that is common for every instance of the model.
More information you can see my branch add/jsonschema
Merged to development. Closing.
Schema validators and data validators:
Form generators (Pretty interesting..)