UNPKG

1.79 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _httpStatus = require('http-status');
8
9var _httpStatus2 = _interopRequireDefault(_httpStatus);
10
11var _scenario = require('../../scenarios/scenario.model');
12
13var _scenario2 = _interopRequireDefault(_scenario);
14
15var _APIError = require('../helpers/APIError');
16
17var _APIError2 = _interopRequireDefault(_APIError);
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21function get(req, res) {
22 return res.json(req.scenario);
23}
24
25function query(req, res, next) {
26 _scenario2.default.findAsync({}).then(function (scenarios) {
27 return res.json(scenarios);
28 }).error(next);
29}
30
31function 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
41function 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
49function 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
57function remove(req, res, next) {
58 req.scenario.removeAsync().then(function (sensor) {
59 res.json(sensor);
60 return next();
61 }).error(next);
62}
63
64exports.default = { get: get, query: query, load: load, create: create, update: update, remove: remove };
65module.exports = exports['default'];
66//# sourceMappingURL=scenario.controller.js.map