0.0.11 | Built motion from commit e8dda05.
[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   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.save()
58         .then(function() {
59           return res.status(200).send(mailServerIn);
60         })
61         .catch(function(err) {
62           console.error(err);
63           return handleError(res, err);
64         });
65     })
66     .catch(function(err) {
67       console.error(err);
68       return handleError(res, err);
69     });
70 };
71
72 // Deletes a mailServerIn from the DB.
73 exports.destroy = function(req, res) {
74   MailServerIn
75     .findById(req.params.id)
76     .then(function(mailServerIn) {
77       if (!mailServerIn) {
78         return res.sendStatus(404);
79       }
80       mailServerIn
81         .destroy()
82         .then(function() {
83           return res.sendStatus(204);
84         })
85         .catch(function(err) {
86
87           return handleError(res, err);
88         });
89     })
90     .catch(function(err) {
91       return handleError(res, err);
92     });
93 };
94
95 function handleError(res, err) {
96   return res.status(500).send(err);
97 }