3 var _ = require('lodash');
4 var UserHasChatRoom = require('../../models').UserHasChatRoom;
6 // Get list of user_has_chat_rooms
7 exports.index = function(req, res) {
10 .then(function (user_has_chat_rooms) {
11 return res.status(200).send(user_has_chat_rooms);
13 .catch(function(err) {
14 return handleError(res, err);
18 // Get a single user_has_chat_room
19 exports.show = function(req, res) {
21 .findById(req.params.id)
22 .then(function (user_has_chat_room) {
23 if(!user_has_chat_room) { return res.sendStatus(404); }
24 return res.send(user_has_chat_room);
27 return handleError(res, err);
31 // Creates a new user_has_chat_room in the DB.
32 exports.create = function(req, res) {
36 .then(function(user_has_chat_room) {
37 return res.status(201).send(user_has_chat_room);
39 .catch(function(err) {
40 return handleError(res, err);
44 // Updates an existing user_has_chat_room in the DB.
45 exports.update = function(req, res) {
50 UserId: req.params.userId,
51 ChatRoomId: req.params.chatRoomId
55 .then(function (user_has_chat_room) {
56 if (!user_has_chat_room) {
57 return res.sendStatus(404);
61 .updateAttributes(req.body)
63 return res.status(200).send(user_has_chat_room);
65 .catch(function(err) {
66 return handleError(res, err);
69 .catch(function(err) {
70 return handleError(res, err);
74 // Deletes a user_has_chat_room from the DB.
75 exports.destroy = function(req, res) {
78 .findById(req.params.id)
79 .then(function (user_has_chat_room) {
80 if(!user_has_chat_room) { return res.sendStatus(404); }
81 user_has_chat_room.destroy()
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);