3 var _ = require('lodash');
4 var UserHasVoiceQueue = require('../../models').UserHasVoiceQueue;
6 // Get list of user_has_voice_queues
7 exports.index = function(req, res) {
12 .then(function(user_has_voice_queues) {
13 return res.status(200).send(user_has_voice_queues);
15 .catch(function(err) {
16 return handleError(res, err);
20 // Get a single userHasVoiceQueue
21 exports.show = function(req, res) {
23 .findById(req.params.id)
24 .then(function(userHasVoiceQueue) {
25 if (!userHasVoiceQueue) {
26 return res.sendStatus(404);
28 return res.send(userHasVoiceQueue);
30 .catch(function(err) {
31 return handleError(res, err);
35 // Creates a new userHasVoiceQueue in the DB.
36 exports.create = function(req, res, next) {
37 console.log(req.body);
40 .then(function(userHasVoiceQueue) {
41 return res.status(201).send(userHasVoiceQueue);
43 .catch(function(err) {
46 // return handleError(res, err);
50 // Updates an existing userHasVoiceQueue in the DB.
51 exports.update = function(req, res) {
56 .findById(req.params.id)
57 .then(function(userHasVoiceQueue) {
58 if (!userHasVoiceQueue) {
59 return res.sendStatus(404);
61 var updated = _.merge(userHasVoiceQueue, req.body);
64 return res.status(200).send(userHasVoiceQueue);
66 .catch(function(err) {
67 return handleError(res, err);
70 .catch(function(err) {
71 return handleError(res, err);
75 // Deletes a userHasVoiceQueue from the DB.
76 exports.destroy = function(req, res) {
78 .findById(req.params.id)
79 .then(function(userHasVoiceQueue) {
80 if (!userHasVoiceQueue) {
81 return res.sendStatus(404);
83 userHasVoiceQueue.destroy()
85 return res.sendStatus(204);
87 .catch(function(err) {
88 return handleError(res, err);
91 .catch(function(err) {
92 return handleError(res, err);
96 function handleError(res, err) {
97 return res.status(500).send(err);