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