3 var _ = require('lodash');
4 var FaxRoom = require('../../models').FaxRoom;
5 var FaxAccount = require('../../models').FaxAccount;
6 var FaxMessage = require('../../models').FaxMessage;
7 var Contact = require('../../models').Contact;
8 var User = require('../../models').User;
10 // Get list of fax_rooms
11 exports.index = function(req, res) {
23 .then(function(fax_rooms) {
24 return res.status(200).send(fax_rooms);
26 .catch(function(err) {
27 return handleError(res, err);
31 // Get list of agent mailRooms
32 exports.agentIndex = function(req, res, next) {
44 .then(function(faxRooms) {
45 return res.status(200).send(faxRooms);
47 .catch(function(err) {
52 // Get a single fax_room
53 exports.show = function(req, res) {
77 [FaxMessage, 'createdAt', 'DESC']
80 .then(function(fax_room) {
82 return res.sendStatus(404);
84 return res.send(fax_room);
86 .catch(function(err) {
87 return handleError(res, err);
91 // Creates a new fax_room in the DB.
92 exports.create = function(req, res) {
95 .then(function(fax_room) {
96 return res.status(201).send(fax_room);
98 .catch(function(err) {
99 return handleError(res, err);
103 // Updates an existing fax_room in the DB.
104 exports.update = function(req, res) {
105 // if (req.body.id) {
106 // delete req.body.id;
109 .findById(req.params.id)
110 .then(function(fax_room) {
112 return res.sendStatus(404);
114 var updated = _.merge(fax_room, req.body);
117 return res.status(200).send(fax_room);
119 .catch(function(err) {
120 return handleError(res, err);
123 .catch(function(err) {
124 return handleError(res, err);
128 // Deletes a fax_room from the DB.
129 exports.destroy = function(req, res) {
131 .findById(req.params.id)
132 .then(function(fax_room) {
134 return res.sendStatus(404);
138 return res.sendStatus(204);
140 .catch(function(err) {
141 return handleError(res, err);
144 .catch(function(err) {
145 return handleError(res, err);
149 function handleError(res, err) {
150 return res.status(500).send(err);