Created
June 21, 2016 20:14
-
-
Save steveinatorx/07d5276921618b9b879ed29027bd8776 to your computer and use it in GitHub Desktop.
keystonejs update http PUT model api call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pattern to get a keystonejs UPDATE model API call working.