3 var _ = require('lodash');
4 var Settings = require('../../models').Settings;
5 var Agent = require('../../models').User;
7 // Get list of settings
8 exports.index = function(req, res) {
11 .then(function(settings) {
12 return res.status(200).send(settings);
14 .catch(function(err) {
15 return handleError(res, err);
19 // Get list of settings
20 exports.getInternal = function(req, res) {
23 .then(function(result) {
28 $gte: result.min_internal
32 .then(function(internals) {
33 var pluckdInternals = _.pluck(_.pluck(internals, 'dataValues'), 'internal');
34 var lastChecked = result.min_internal;
35 var internalNumber = {
39 if (pluckdInternals.indexOf(lastChecked) === -1) {
40 internalNumber.value = lastChecked;
44 } while (!internalNumber.value)
45 return res.status(200).send(internalNumber);
47 .catch(function(err) {
49 return handleError(res, err);
52 .catch(function(err) {
53 return handleError(res, err);
57 // Get list of settings
58 exports.getInfo = function(req, res) {
60 var info = require('../../../package.json');
62 return res.status(200).send({
64 version: info.version,
69 // Get a single setting
70 exports.show = function(req, res) {
72 .findById(req.params.id)
73 .then(function(setting) {
75 return res.sendStatus(404);
77 return res.send(setting);
79 .catch(function(err) {
80 return handleError(res, err);
84 // Creates a new setting in the DB.
85 exports.create = function(req, res) {
88 .then(function(setting) {
89 return res.status(201).send(setting);
91 .catch(function(err) {
92 return handleError(res, err);
96 // Updates an existing setting in the DB.
97 exports.update = function(req, res) {
107 .then(function(setting) {
109 return res.sendStatus(404);
111 var updated = _.merge(setting, req.body);
114 return res.status(200).send(setting);
116 .catch(function(err) {
117 return handleError(res, err);
120 .catch(function(err) {
121 return handleError(res, err);
125 // Deletes a setting from the DB.
126 exports.destroy = function(req, res) {
133 .then(function(setting) {
135 return res.sendStatus(404);
139 return res.sendStatus(204);
141 .catch(function(err) {
142 return handleError(res, err);
145 .catch(function(err) {
146 return handleError(res, err);
150 function handleError(res, err) {
151 return res.status(500).send(err);