in a project with sails, I have created a car model:
// Coche.js
module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
color: {
type: 'string',
required: false
},
price: {
type: 'number,
required: true
}
}
}
With this, the sails themselves have their own endpoints with / car, so I can have the get, post, delete ...
Now, I need to create an endpoint / car / validate itself (I just need to validate the post with the model, then I call a service with the data NOT STORED in BBDD). I've defined it like this:
(module).exports = function api(sails) {
return {
initialize: function(cb) {
sails.on('router:after', function() {
sails.router.bind('/coche/validate', validate, 'post', {});
});
function validate(req: Request, res: Response, next: Function) {
/**
como puedo "validar" mi modelo coche, si lo que tengo es req y res?
con req.body obtengo los parametros de post, pero todos son string.
**/ return(res.json(resultado));
}
return cb();
},
}
The problem is that I do not really know how to link or work with the model, in this action. The ones of get, post and delete of / car are "auto-magicas" of the own sails ...
Is there any way to check the post (with req.body I get an array with the fields that arrive in the post) and validate with some function of sails that data with the model ????