Built motion from commit 06df96e on branch develop.
[motion.git] / server / api / mail_server_in / mail_server_in.controller.js
1 'use strict';
2
3 var _ = require('lodash');
4 var MailServerIn = require('../../models').MailServerIn;
5
6 // Get list of mail_server_ins
7 exports.index = function(req, res) {
8   MailServerIn
9   .findAll()
10   .then(function (mail_server_ins) {
11     return res.status(200).send(mail_server_ins);
12   })
13   .catch(function(err) {
14     return handleError(res, err);
15   });
16 };
17
18 // Get a single mail_server_in
19 exports.show = function(req, res) {
20   MailServerIn
21   .findById(req.params.id)
22   .then(function (mail_server_in) {
23     if(!mail_server_in) { return res.sendStatus(404); }
24     return res.send(mail_server_in);
25   })
26   .catch(function(err){
27     return handleError(res, err);
28   });
29 };
30
31 // Creates a new mail_server_in in the DB.
32 exports.create = function(req, res) {
33   MailServerIn
34   .create(req.body)
35   .then(function(mail_server_in) {
36     return res.status(201).send(mail_server_in);
37   })
38   .catch(function(err) {
39     return handleError(res, err);
40   });
41 };
42
43 // Updates an existing mail_server_in in the DB.
44 exports.update = function(req, res) {
45   if(req.body.id) { delete req.body.id; }
46   MailServerIn
47   .findById(req.params.id)
48   .then(function (mail_server_in) {
49     if(!mail_server_in) { return res.sendStatus(404); }
50     var updated = _.merge(mail_server_in, req.body);
51     updated.save()
52     .then(function () {
53       return res.status(200).send(mail_server_in);
54     })
55     .catch(function(err) {
56       return handleError(res, err);
57     });
58   })
59   .catch(function(err) {
60     return handleError(res, err);
61   });
62 };
63
64 // Deletes a mail_server_in from the DB.
65 exports.destroy = function(req, res) {
66   MailServerIn
67   .findById(req.params.id)
68   .then(function (mail_server_in) {
69     if(!mail_server_in) { return res.sendStatus(404); }
70     mail_server_in.destroy()
71     .then(function() {
72       return res.sendStatus(204);
73     })
74     .catch(function(err) {
75       return handleError(res, err);
76     });
77   })
78   .catch(function(err) {
79     return handleError(res, err);
80   });
81 };
82
83 function handleError(res, err) {
84   return res.status(500).send(err);
85 }