Built motion from commit 5e31ea4.|0.0.32
[motion.git] / server / api / report_chat_session / report_chat_session.controller.js
1 'use strict';
2
3 var _ = require('lodash');
4 var ReportChatSession = require('../../models').ReportChatSession;
5
6 // Get list of report_chat_sessions
7 exports.index = function(req, res) {
8   ReportChatSession
9     .findAll()
10     .then(function(report_chat_sessions) {
11       return res.status(200).send(report_chat_sessions);
12     })
13     .catch(function(err) {
14       return handleError(res, err);
15     });
16 };
17
18 // Get list of fields
19 exports.describe = function(req, res) {
20   ReportChatSession
21     .describe()
22     .then(function(fields) {
23       return res.status(200).send(fields);
24     })
25     .catch(function(err) {
26       return handleError(res, err);
27     });
28 };
29
30 // Get a single report_chat_session
31 exports.show = function(req, res) {
32   ReportChatSession
33     .findById(req.params.id)
34     .then(function(report_chat_session) {
35       if (!report_chat_session) {
36         return res.sendStatus(404);
37       }
38       return res.send(report_chat_session);
39     })
40     .catch(function(err) {
41       return handleError(res, err);
42     });
43 };
44
45 // Creates a new report_chat_session in the DB.
46 exports.create = function(req, res) {
47   ReportChatSession
48     .create(req.body)
49     .then(function(report_chat_session) {
50       return res.status(201).send(report_chat_session);
51     })
52     .catch(function(err) {
53       return handleError(res, err);
54     });
55 };
56
57 // Updates an existing report_chat_session in the DB.
58 exports.update = function(req, res) {
59   if (req.body.id) {
60     delete req.body.id;
61   }
62   ReportChatSession
63     .find({
64       where: {
65         id: req.params.id
66       }
67     })
68     .then(function(report_chat_session) {
69       if (!report_chat_session) {
70         return res.sendStatus(404);
71       }
72       var updated = _.merge(report_chat_session, req.body);
73       updated.save()
74         .then(function() {
75           return res.status(200).send(report_chat_session);
76         })
77         .catch(function(err) {
78           return handleError(res, err);
79         });
80     })
81     .catch(function(err) {
82       return handleError(res, err);
83     });
84 };
85
86 // Deletes a report_chat_session from the DB.
87 exports.destroy = function(req, res) {
88   ReportChatSession
89     .find({
90       where: {
91         id: req.params.id
92       }
93     })
94     .then(function(report_chat_session) {
95       if (!report_chat_session) {
96         return res.sendStatus(404);
97       }
98       report_chat_session.destroy()
99         .then(function() {
100           return res.sendStatus(204);
101         })
102         .catch(function(err) {
103           return handleError(res, err);
104         });
105     })
106     .catch(function(err) {
107       return handleError(res, err);
108     });
109 };
110
111 function handleError(res, err) {
112   return res.status(500).send(err);
113 }