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);
19 exports.describe = function(req, res) {
22 .then(function(fields) {
23 return res.status(200).send(fields);
25 .catch(function(err) {
26 return handleError(res, err);
30 // Get a single report_chat_session
31 exports.show = function(req, res) {
33 .findById(req.params.id)
34 .then(function(report_chat_session) {
35 if (!report_chat_session) {
36 return res.sendStatus(404);
38 return res.send(report_chat_session);
40 .catch(function(err) {
41 return handleError(res, err);
45 // Creates a new report_chat_session in the DB.
46 exports.create = function(req, res) {
49 .then(function(report_chat_session) {
50 return res.status(201).send(report_chat_session);
52 .catch(function(err) {
53 return handleError(res, err);
57 // Updates an existing report_chat_session in the DB.
58 exports.update = function(req, res) {
68 .then(function(report_chat_session) {
69 if (!report_chat_session) {
70 return res.sendStatus(404);
72 var updated = _.merge(report_chat_session, req.body);
75 return res.status(200).send(report_chat_session);
77 .catch(function(err) {
78 return handleError(res, err);
81 .catch(function(err) {
82 return handleError(res, err);
86 // Deletes a report_chat_session from the DB.
87 exports.destroy = function(req, res) {
94 .then(function(report_chat_session) {
95 if (!report_chat_session) {
96 return res.sendStatus(404);
98 report_chat_session.destroy()
100 return res.sendStatus(204);
102 .catch(function(err) {
103 return handleError(res, err);
106 .catch(function(err) {
107 return handleError(res, err);
111 function handleError(res, err) {
112 return res.status(500).send(err);