4b9bb681babd776991657a84b3db5b5daa4dd306
[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 mailServerIn
19 exports.show = function (req, res) {
20   MailServerIn
21     .findById(req.params.id)
22     .then(function (mailServerIn) {
23       if (!mailServerIn) {
24         return res.sendStatus(404);
25       }
26       return res.send(mailServerIn);
27     })
28     .catch(function (err) {
29       return handleError(res, err);
30     });
31 };
32
33 // Creates a new mailServerIn in the DB.
34 exports.create = function (req, res) {
35   MailServerIn
36     .create(req.body)
37     .then(function (mailServerIn) {
38       return res.status(201).send(mailServerIn);
39     })
40     .catch(function (err) {
41       return handleError(res, err);
42     });
43 };
44
45 // Updates an existing mailServerIn in the DB.
46 exports.update = function (req, res) {
47   if (req.body.id) {
48     delete req.body.id;
49   }
50   return MailServerIn
51     .findById(req.params.id)
52     .then(function (mailServerIn) {
53       if (!mailServerIn) {
54         return res.sendStatus(404);
55       }
56       var updated = _.merge(mailServerIn, req.body);
57       updated
58         .save()
59         .then(function () {
60           return res.status(200).send(mailServerIn);
61         })
62         .catch(function (err) {
63           console.error(err);
64           return handleError(res, err);
65         });
66     })
67     .catch(function (err) {
68       console.error(err);
69       return handleError(res, err);
70     });
71 };
72
73 // Deletes a mailServerIn from the DB.
74 exports.destroy = function (req, res) {
75   MailServerIn
76     .findById(req.params.id)
77     .then(function (mailServerIn) {
78       if (!mailServerIn) {
79         return res.sendStatus(404);
80       }
81       mailServerIn
82         .destroy()
83         .then(function () {
84           return res.sendStatus(204);
85         })
86         .catch(function (err) {
87
88           return handleError(res, err);
89         });
90     })
91     .catch(function (err) {
92       return handleError(res, err);
93     });
94 };
95
96 function handleError(res, err) {
97   return res.status(500).send(err);
98 }