3 var _ = require('lodash');
4 var ReportChatSession = require('../../models').ReportChatSession;
6 // Get list of report_chat_sessions
7 exports.index = function(req, res) {
10 .then(function (report_chat_sessions) {
11 return res.status(200).send(report_chat_sessions);
13 .catch(function(err) {
14 return handleError(res, err);
18 // Get a single report_chat_session
19 exports.show = function(req, res) {
21 .findById(req.params.id)
22 .then(function (report_chat_session) {
23 if(!report_chat_session) { return res.sendStatus(404); }
24 return res.send(report_chat_session);
27 return handleError(res, err);
31 // Creates a new report_chat_session in the DB.
32 exports.create = function(req, res) {
35 .then(function(report_chat_session) {
36 return res.status(201).send(report_chat_session);
38 .catch(function(err) {
39 return handleError(res, err);
43 // Updates an existing report_chat_session in the DB.
44 exports.update = function(req, res) {
45 if(req.body.id) { delete req.body.id; }
52 .then(function (report_chat_session) {
53 if(!report_chat_session) { return res.sendStatus(404); }
54 var updated = _.merge(report_chat_session, req.body);
57 return res.status(200).send(report_chat_session);
59 .catch(function(err) {
60 return handleError(res, err);
63 .catch(function(err) {
64 return handleError(res, err);
68 // Deletes a report_chat_session from the DB.
69 exports.destroy = function(req, res) {
76 .then(function (report_chat_session) {
77 if(!report_chat_session) { return res.sendStatus(404); }
78 report_chat_session.destroy()
80 return res.sendStatus(204);
82 .catch(function(err) {
83 return handleError(res, err);
86 .catch(function(err) {
87 return handleError(res, err);
91 function handleError(res, err) {
92 return res.status(500).send(err);