3 var _ = require('lodash');
4 var fs = require('fs');
5 var MailAttachment = require('../../models').MailAttachment;
7 // Get list of mailAttachments
8 exports.index = function (req, res, next) {
11 .then(function (mailAttachments) {
12 return res.status(200).send(mailAttachments);
14 .catch(function (err) {
19 // Get a single mailAttachment
20 exports.show = function (req, res, next) {
22 .findById(req.params.id)
23 .then(function (mailAttachment) {
24 res.download(mailAttachment.path, mailAttachment.fileName);
26 .catch(function (err) {
31 // Creates a new mailAttachment in the DB.
32 exports.create = function (req, res, next) {
35 .then(function (mailAttachment) {
36 return res.status(201).send(mailAttachment);
38 .catch(function (err) {
43 // Updates an existing mailAttachment in the DB.
44 exports.update = function (req, res, next) {
49 .findById(req.params.id)
50 .then(function (mailAttachment) {
51 if (!mailAttachment) {
52 return res.sendStatus(404);
54 var updated = _.merge(mailAttachment, req.body);
57 return res.status(200).send(mailAttachment);
59 .catch(function (err) {
63 .catch(function (err) {
68 // Deletes a mailAttachment from the DB.
69 exports.destroy = function (req, res, next) {
71 .findById(req.params.id)
72 .then(function (mailAttachment) {
73 if (!mailAttachment) {
74 return res.sendStatus(404);
76 mailAttachment.destroy()
78 return res.sendStatus(204);
80 .catch(function (err) {
84 .catch(function (err) {