2 var _ = require('lodash');
3 var MailApplication = require('../../models').MailApplication;
4 // Get list of mailApplications
5 exports.index = function(req, res, next) {
14 .then(function(mailApplications) {
15 return res.status(200).send(mailApplications);
17 .catch(function(err) {
18 return handleError(res, err);
21 // Get a single mailApplication
22 exports.show = function(req, res, next) {
24 .findById(req.params.id, {
29 .then(function(mailApplication) {
30 if (!mailApplication) {
31 return res.sendStatus(404);
33 return res.send(mailApplication);
35 .catch(function(err) {
36 return handleError(res, err);
39 // Creates a new mailApplication in the DB.
40 exports.create = function(req, res, next) {
44 MailAccountId: req.body.MailAccountId
46 }).then(function(max) {
48 req.body.priority = max ? ++max : 1;
51 .then(function(mailApplication) {
52 return res.status(201).send(mailApplication);
54 .catch(function(err) {
55 return handleError(res, err);
58 .catch(function(err) {
59 return handleError(res, err);
62 // Updates an existing mailApplication in the DB.
63 exports.update = function(req, res, next) {
68 .findById(req.params.id)
69 .then(function(mailApplication) {
70 if (!mailApplication) {
71 return res.sendStatus(404);
73 var updated = _.merge(mailApplication, req.body);
77 return res.status(200).send(mailApplication);
79 .catch(function(err) {
80 return handleError(res, err);
83 .catch(function(err) {
84 return handleError(res, err);
87 // Deletes a mailApplication from the DB.
88 exports.destroy = function(req, res, next) {
90 .findById(req.params.id)
91 .then(function(mailApplication) {
92 if (!mailApplication) {
93 return res.sendStatus(404);
98 return res.sendStatus(204);
100 .catch(function(err) {
101 return handleError(res, err);
104 .catch(function(err) {
105 return handleError(res, err);
109 function handleError(res, err) {
110 return res.status(500).send(err);