1 | [![Build Status](https://travis-ci.org/stonecircle/express-autoroute-json.svg?branch=master)](https://travis-ci.org/stonecircle/express-autoroute-json)
|
2 | [![devDependency Status](https://david-dm.org/stonecircle/express-autoroute-json/dev-status.svg?theme=shields.io)](https://david-dm.org/stonecircle/express-autoroute-json#info=devDependencies)
|
3 | [![Code Climate](https://codeclimate.com/github/stonecircle/express-autoroute-json/badges/gpa.svg)](https://codeclimate.com/github/stonecircle/express-autoroute-json)
|
4 | [![Test Coverage](https://codeclimate.com/github/stonecircle/express-autoroute-json/badges/coverage.svg)](https://codeclimate.com/github/stonecircle/express-autoroute-json/coverage)
|
5 |
|
6 | # Documentation Pending
|
7 | We have just completed the rewrite and express-autoroute-json now speaks [JSON:API](https://jsonapi.org)
|
8 |
|
9 | We will be working on documentation over the coming weeks
|
10 |
|
11 | ```
|
12 | npm install express-autoroute-json@prerelease
|
13 | ```
|
14 |
|
15 | and use this in your route file just like before:
|
16 |
|
17 | ```
|
18 | var autorouteJson = require('express-autoroute-json');
|
19 |
|
20 | //get your mongoose models
|
21 | var models = rootRequire('./db/models');
|
22 |
|
23 | function isAdmin(req, res, next) {
|
24 | //deny access if the user is not admin
|
25 | if (!req.user || !req.user.isAdmin) {
|
26 | return res.status(401).send("You are not an admin");
|
27 | }
|
28 | next();
|
29 | }
|
30 |
|
31 | module.exports.autoroute = autorouteJson({
|
32 | model: models.account,
|
33 | resource: 'account', //this will be pluralised in the routes
|
34 | authentication: isAdmin, //this is used for all the following functions
|
35 |
|
36 | //default CRUD
|
37 | find: {},
|
38 | create: {},
|
39 | update: {},
|
40 | delete: {}
|
41 | });
|
42 | ```
|
43 |
|
44 | # Licence
|
45 | Copyright (c) 2016, Stone Circle <info@stonecircle.ie>
|
46 |
|
47 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
48 |
|
49 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
50 |
|
51 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|