Last active
December 25, 2018 22:01
-
-
Save developit/ec2f438efc5feea4fd3a to your computer and use it in GitHub Desktop.
Revisions
-
developit revised this gist
Mar 15, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,16 +24,16 @@ export default function(name, model) { }, read({ params }, res) { model.findById(params[name], toRes(res)); }, update({ body, params }, res) { delete body._id; model.findByIdAndUpdate(params[name], { $set:body }, toRes(res)); }, delete(req, res) { model.findByIdAndRemove(params[name], toRes(res)); } }); } -
developit created this gist
Apr 8, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ import mongooseResource from '../lib/mongoose-resource'; import Foo from '../models/foo'; // a mongoose Model export default mongooseResource('foo', Foo); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import resource from 'resource-router-middleware'; import { toRes } from './util'; export default function(name, model) { return resource({ id : name, list({ params }, res) { var limit = Math.max(1, Math.min(50, params.limit|0 || 10)); if (params.search) { return model.textSearch(params.search, { limit : limit, language : 'en', lean : true }, toRes(res)); } model.find({}).skip(params.start|0 || 0).limit(limit).exec(toRes(res)); }, create({ body }, res) { model.create(body, toRes(res)); }, read({ params }, res) { model.findById(params[this.id], toRes(res)); }, update({ body, params }, res) { delete body._id; model.findByIdAndUpdate(params[this.id], { $set:body }, toRes(res)); }, delete(req, res) { model.findByIdAndRemove(params[this.id], toRes(res)); } }); }