3 var _ = require('lodash');
4 var ChatEnquiry = require('../../models').ChatEnquiry;
5 var ChatVisitor = require('../../models').ChatVisitor;
7 // Get list of enquirys
8 exports.index = function(req, res) {
11 .then(function(enquirys) {
12 return res.status(200).send(enquirys);
14 .catch(function(err) {
15 return handleError(res, err);
19 // Get a single enquiry
20 exports.show = function(req, res) {
26 include: [ChatVisitor]
28 .then(function(enquiry) {
30 return res.sendStatus(404);
32 return res.send(enquiry);
34 .catch(function(err) {
35 return handleError(res, err);
39 // Creates a new enquiry in the DB.
40 exports.create = function(req, res) {
43 .then(function(enquiry) {
44 return res.status(201).send(enquiry);
46 .catch(function(err) {
47 return handleError(res, err);
51 // Updates an existing enquiry in the DB.
52 exports.update = function(req, res) {
57 .findById(req.params.id)
58 .then(function(enquiry) {
60 return res.sendStatus(404);
62 var updated = _.merge(enquiry, req.body);
65 return res.status(200).send(enquiry);
67 .catch(function(err) {
68 return handleError(res, err);
71 .catch(function(err) {
72 return handleError(res, err);
76 // Deletes a enquiry from the DB.
77 exports.destroy = function(req, res) {
79 .findById(req.params.id)
80 .then(function(enquiry) {
82 return res.sendStatus(404);
86 return res.sendStatus(204);
88 .catch(function(err) {
89 return handleError(res, err);
92 .catch(function(err) {
93 return handleError(res, err);
97 function handleError(res, err) {
98 return res.status(500).send(err);