3 var _ = require('lodash');
4 var ChatVisitor = require('../../models').ChatVisitor;
6 // Get list of chat_visitors
7 exports.index = function(req, res) {
10 .then(function(chat_visitors) {
11 return res.status(200).send(chat_visitors);
13 .catch(function(err) {
14 return handleError(res, err);
18 // Get a single chat_visitor
19 exports.show = function(req, res) {
21 .findById(req.params.id)
22 .then(function(chat_visitor) {
24 return res.sendStatus(404);
26 return res.send(chat_visitor);
28 .catch(function(err) {
29 return handleError(res, err);
33 // Creates a new chat_visitor in the DB.
34 exports.create = function(req, res) {
38 .then(function(chat_visitor) {
39 return res.status(201).send(chat_visitor);
41 .catch(function(err) {
42 return handleError(res, err);
46 // Updates an existing chat_visitor in the DB.
47 exports.update = function(req, res) {
52 .findById(req.params.id)
53 .then(function(chat_visitor) {
55 return res.sendStatus(404);
57 var updated = _.merge(chat_visitor, req.body);
60 return res.status(200).send(chat_visitor);
62 .catch(function(err) {
63 return handleError(res, err);
66 .catch(function(err) {
67 return handleError(res, err);
71 // Deletes a chat_visitor from the DB.
72 exports.destroy = function(req, res) {
74 .findById(req.params.id)
75 .then(function(chat_visitor) {
77 return res.sendStatus(404);
79 chat_visitor.destroy()
81 return res.sendStatus(204);
83 .catch(function(err) {
84 return handleError(res, err);
87 .catch(function(err) {
88 return handleError(res, err);
92 function handleError(res, err) {
93 return res.status(500).send(err);