3 var _ = require('lodash');
4 var ReportChat = require('../../models').ReportChat;
5 var sequelize = require('../../models').sequelize;
7 // Get list of report_chats
8 exports.index = function (req, res) {
11 .then(function (report_chats) {
12 return res.status(200).send(report_chats);
14 .catch(function (err) {
15 return handleError(res, err);
19 // Get a single reportChat
20 exports.show = function (req, res) {
22 .findById(req.params.id)
23 .then(function (reportChat) {
25 return res.sendStatus(404);
27 return res.send(reportChat);
29 .catch(function (err) {
30 return handleError(res, err);
34 // Creates a new reportChat in the DB.
35 exports.create = function (req, res) {
38 .then(function (reportChat) {
39 return res.status(201).send(reportChat);
41 .catch(function (err) {
42 return handleError(res, err);
46 // Updates an existing reportChat in the DB.
47 exports.update = function (req, res, next) {
53 .findById(req.params.id)
54 .then(function (reportChat) {
56 return res.sendStatus(404);
58 var updated = _.merge(reportChat, req.body);
62 return res.status(200).send(reportChat);
65 .catch(sequelize.ValidationError, function (err) {
66 return handleError(res, err);
68 .catch(function (err) {
69 return handleError(res, err);
73 // Deletes a reportChat from the DB.
74 exports.destroy = function (req, res) {
76 .findById(req.params.id)
77 .then(function (reportChat) {
79 return res.sendStatus(404);
83 return res.sendStatus(204);
85 .catch(function (err) {
86 return handleError(res, err);
89 .catch(function (err) {
90 return handleError(res, err);
94 function handleError(res, err) {
95 return res.status(500).send(err);