1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _httpStatus = require('http-status');
|
8 |
|
9 | var _httpStatus2 = _interopRequireDefault(_httpStatus);
|
10 |
|
11 | var _scenario = require('../../scenarios/scenario.model');
|
12 |
|
13 | var _scenario2 = _interopRequireDefault(_scenario);
|
14 |
|
15 | var _APIError = require('../helpers/APIError');
|
16 |
|
17 | var _APIError2 = _interopRequireDefault(_APIError);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | function get(req, res) {
|
22 | return res.json(req.scenario);
|
23 | }
|
24 |
|
25 | function query(req, res, next) {
|
26 | _scenario2.default.findAsync({}).then(function (scenarios) {
|
27 | return res.json(scenarios);
|
28 | }).error(next);
|
29 | }
|
30 |
|
31 | function load(req, res, next, id) {
|
32 | _scenario2.default.get(id).then(function (scenario) {
|
33 | req.scenario = scenario;
|
34 | return next();
|
35 | }).error(function () {
|
36 | var err = new _APIError2.default('No such scenario exists!', _httpStatus2.default.NOT_FOUND);
|
37 | return next(err);
|
38 | });
|
39 | }
|
40 |
|
41 | function create(req, res, next) {
|
42 | var instance = new _scenario2.default(req.body);
|
43 |
|
44 | instance.saveAsync().then(function (scenario) {
|
45 | return res.json(scenario);
|
46 | }).error(next);
|
47 | }
|
48 |
|
49 | function update(req, res, next) {
|
50 | delete req.body.id;
|
51 | Object.assign(req.scenario, req.body);
|
52 | req.scenario.saveAsync().then(function () {
|
53 | return res.json(req.scenario);
|
54 | }).error(next);
|
55 | }
|
56 |
|
57 | function remove(req, res, next) {
|
58 | req.scenario.removeAsync().then(function (sensor) {
|
59 | res.json(sensor);
|
60 | return next();
|
61 | }).error(next);
|
62 | }
|
63 |
|
64 | exports.default = { get: get, query: query, load: load, create: create, update: update, remove: remove };
|
65 | module.exports = exports['default'];
|
66 | //# sourceMappingURL=scenario.controller.js.map
|