Skip to content

Instantly share code, notes, and snippets.

@steveinatorx
Created June 21, 2016 20:14
Show Gist options
  • Save steveinatorx/07d5276921618b9b879ed29027bd8776 to your computer and use it in GitHub Desktop.
Save steveinatorx/07d5276921618b9b879ed29027bd8776 to your computer and use it in GitHub Desktop.
keystonejs update http PUT model api call
var keystone = require('keystone');
var TheModel=keystone.list('TheModel');
var _=require('lodash');
exports.update=function(req, res) {
TheModel.model.findOneAndUpdate({"id":req.params.id},{$set:req.body},{new:true},function(err, doc) {
if (err) return res.apiError('error', err);
res.apiResponse({
themodel: doc
});
});
};
/* took a minute to figure out hoe to properly update models in keystone via an api call - here is my solution using an http PUT */
exports = module.exports = function(app) {
//...other routes
app.put('/api/themodel/:id', keystone.middleware.api, routes.api.themodel.update);
};
@steveinatorx
Copy link
Author

Pattern to get a keystonejs UPDATE model API call working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment