I am new to Sails and trying to learn CRUD functions to make my first api, with the help of Ponzi Coder tutorials, How do I create a restful json CRUD api in sails from scratch?
For the Update request, I tried this piece of code for my application "Small",
module.exports = {
update: function (req, res, next) {
var criteria = {};
criteria = _.merge({}, req.params.all(), req.body);
var id = req.param('id');
if (!id) {
return res.badRequest('No id provided.');
}
small.update(id, criteria, function (err, small) {
if (err) return next(err);
if (small.length == 0) return res.notFound();
res.json(small);
});
}
}
but I am unable to understand the significance and role of criteria array and the second argument for update function
small.update(id, criteria, function (err, small) {...});
I got it that criteria will be specifying the changes we want to update, but how ?
Somebody please help me out to get a better understanding of this.