|
| 1 | +// InstallationsRouter.js |
| 2 | + |
| 3 | +import ClassesRouter from './ClassesRouter'; |
| 4 | +import PromiseRouter from '../PromiseRouter'; |
| 5 | +import rest from '../rest'; |
| 6 | + |
| 7 | +export class InstallationsRouter extends ClassesRouter { |
| 8 | + handleFind(req) { |
| 9 | + var options = {}; |
| 10 | + if (req.body.skip) { |
| 11 | + options.skip = Number(req.body.skip); |
| 12 | + } |
| 13 | + if (req.body.limit) { |
| 14 | + options.limit = Number(req.body.limit); |
| 15 | + } |
| 16 | + if (req.body.order) { |
| 17 | + options.order = String(req.body.order); |
| 18 | + } |
| 19 | + if (req.body.count) { |
| 20 | + options.count = true; |
| 21 | + } |
| 22 | + if (req.body.include) { |
| 23 | + options.include = String(req.body.include); |
| 24 | + } |
| 25 | + |
| 26 | + return rest.find(req.config, req.auth, |
| 27 | + '_Installation', req.body.where, options) |
| 28 | + .then((response) => { |
| 29 | + return {response: response}; |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + handleGet(req) { |
| 34 | + req.params.className = '_Installation'; |
| 35 | + return super.handleGet(req); |
| 36 | + } |
| 37 | + |
| 38 | + handleCreate(req) { |
| 39 | + req.params.className = '_Installation'; |
| 40 | + return super.handleCreate(req); |
| 41 | + } |
| 42 | + |
| 43 | + handleUpdate(req) { |
| 44 | + req.params.className = '_Installation'; |
| 45 | + return super.handleUpdate(req); |
| 46 | + } |
| 47 | + |
| 48 | + handleDelete(req) { |
| 49 | + req.params.className = '_Installation'; |
| 50 | + return super.handleDelete(req); |
| 51 | + } |
| 52 | + |
| 53 | + getExpressRouter() { |
| 54 | + var router = new PromiseRouter(); |
| 55 | + router.route('GET','/installations', (req) => { return this.handleFind(req); }); |
| 56 | + router.route('GET','/installations/:objectId', (req) => { return this.handleGet(req); }); |
| 57 | + router.route('POST','/installations', (req) => { return this.handleCreate(req); }); |
| 58 | + router.route('PUT','/installations/:objectId', (req) => { return this.handleUpdate(req); }); |
| 59 | + router.route('DELETE','/installations/:objectId', (req) => { return this.handleDelete(req); }); |
| 60 | + return router; |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +export default InstallationsRouter; |
0 commit comments