osmlab / to-fix-backend

The to-fix server
BSD 3-Clause "New" or "Revised" License
15 stars 13 forks source link

Encapsulate query parameter validation as a module #176

Open batpad opened 6 years ago

batpad commented 6 years ago

Right now, we're doing validation inside each end-point where we expect data.

A lot of the validation rules are similar across end-points. We should use a library or a mechanism to reduce a lot of the validation logic in individual end-points and delegate to a validation module.

Not urgent at all, just wanted to ticket - if I stumble across any libraries that seem good for this, will drop into this ticket.

cc @emilymdubois

batpad commented 6 years ago

This looks maybe decent: https://booker.codes/input-validation-in-express-with-express-validator/

batpad commented 6 years ago

And for validation things that are being saved to the model, we should be able to define the validators we need on the model definition itself, as per http://docs.sequelizejs.com/manual/tutorial/models-definition.html#validations -- and then ideally be able to catch the ValidationError raised and return the response to the user.