0

New to sails.js and was using the auto generated default api's but then I want to know if ...

New to sails.js and was using the auto generated default api’s but then I want to know if I could add just a little customization to it without having to rewrite the whole code for it again.

at the moment, i wanted to customize the /create api and so wrote this code

`create:function(req,res){
var username = req.query.username;
var password = req.query.password;
if(password===‘faraz’){
res.send(‘cant set password to faraz’);
}else if(!password){
res.send(‘cant set blank password’);
}else{
TestAPI.create(req.query).exec(function(err,newUser){
if(err){
res.send(err);
}
var username = newUser.username;
var createdUser = {username:username};
res.send(createdUser);
});
}

}`

now, in the above code I have written the full code here, with the validation and then using the create api myself. so, the automatically generated api was not very useful here as I had to write everything myself. so, what exactly is the use of these shortcut api’s if i still need to write the whole thing to just add validation.

or maybe I am missing something. in that case, tell me how you would add validation to the /create without having to write the whole thing.

Escribe tu comentario
+ 2