web-crud
Web application CRUD Node and Mongoose
- list
- create
- findById
- update
- delete
Installation
$ npm install web-crud --save
Example
model/foo.js
'use strict'; const mongoose = ;const Schema = mongooseSchema; const FooSchema = name: type: String required: true last_name: type: String required: true full_name: type: String required: true ; moduleexports = mongoose;
controller/foo.js
'use strict'; const Model = ;const Crud = ; Crud; // set model mongoose moduleexports = // if you want to override static { reqbodyfull_name = ` ` super; // call the super method or not :) }; ;
route/foo.js
'use strict'; const express = ;const router = express;const controller = ; router router moduleexports = router;
List method accepts common query parameters. To prevent column name confusion, some of those parameter are prefixed with underscore.
- Find
/myapiurl/list?my_object_propertie=SomeValue
According to: http://mongoosejs.com/docs/api.html#query_Query-find
- Limit
/myapiurl/list?_limit=10
According to: http://mongoosejs.com/docs/api.html#query_Query-limit
- Skip
/myapiurl/list?_skip=5
According to: http://mongoosejs.com/docs/api.html#query_Query-skip
- Sort
/myapiurl/list?_sort=property_name/myapiurl/list?_sort=-property_name
According to: http://mongoosejs.com/docs/api.html#query_Query-sort
- Count
/myapiurl/list?_count=true
According to: http://mongoosejs.com/docs/api.html#query_Query-count