https://github.com/danielrohers/web-crud
Web application CRUD Node and Mongoose
https://github.com/danielrohers/web-crud
Last synced: 9 months ago
JSON representation
Web application CRUD Node and Mongoose
- Host: GitHub
- URL: https://github.com/danielrohers/web-crud
- Owner: danielrohers
- License: other
- Created: 2015-12-27T15:27:22.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-04T14:05:25.000Z (over 10 years ago)
- Last Synced: 2025-09-17T04:35:04.698Z (9 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/web-crud
- Size: 8.79 KB
- Stars: 16
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# web-crud
Web application CRUD Node and Mongoose
- list
- create
- findById
- update
- delete
[](https://badge.fury.io/js/web-crud)
[](https://www.npmjs.com/package/web-crud)
## Installation
```sh
$ npm install web-crud --save
```
### Example
##### model/foo.js
```js
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const FooSchema = new Schema({
name: {
type: String,
required: true
},
last_name: {
type: String,
required: true
},
full_name: {
type: String,
required: true
},
});
module.exports = mongoose.model('Foo', FooSchema);
```
##### controller/foo.js
```js
'use strict';
const Model = require('./model/foo');
const Crud = require('web-crud');
Crud.model(Model); // set model mongoose
module.exports = class Foo extends Crud {
// if you want to override
static create (req, res) {
req.body.full_name = `${req.body.name} ${req.body.last_name}`
super.create(req, res); // call the super method or not :)
};
};
```
##### route/foo.js
```js
'use strict';
const express = require('express');
const router = express.Router();
const controller = require('./controller/foo');
router
.route('/')
.get(controller.list)
.post(controller.create)
router
.route('/:id')
.get(controller.findById)
.put(controller.update)
.delete(controller.delete)
module.exports = router;
```
List method accepts common query parameters. To prevent column name confusion, some of those parameter are prefixed with underscore.
* Find
```js
/myapiurl/list?my_object_propertie=SomeValue
```
According to: http://mongoosejs.com/docs/api.html#query_Query-find
* Limit
```js
/myapiurl/list?_limit=10
```
According to: http://mongoosejs.com/docs/api.html#query_Query-limit
* Skip
```js
/myapiurl/list?_skip=5
```
According to: http://mongoosejs.com/docs/api.html#query_Query-skip
* Sort
```js
/myapiurl/list?_sort=property_name
/myapiurl/list?_sort=-property_name
```
According to: http://mongoosejs.com/docs/api.html#query_Query-sort
* Count
```js
/myapiurl/list?_count=true
```
According to: http://mongoosejs.com/docs/api.html#query_Query-count
## Technologies
- [Node.js](https://nodejs.org)
## License
[MIT](LICENSE)