Skip to content

Commit

Permalink
Updates to Queue controller
Browse files Browse the repository at this point in the history
  • Loading branch information
itajenglish committed Mar 2, 2017
1 parent c3aa26b commit bed683e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const USERS_ROUTER = require('./controllers/Users');
const SESSIONS_ROUTER = require('./controllers/Sessions');
const HOME_ROUTER = require('./controllers/Home');
const DASHBOARDS_ROUTER = require('./controllers/Dashboards');
const QUEUE_ROUTER = require('./controllers/Queue');
const API_ROUTER = require('./controllers/API');

const checkSession = require('./lib/helpers/checkSession');
Expand Down Expand Up @@ -54,6 +55,7 @@ app.listen(PORT, function() {
app.use('/', HOME_ROUTER);
app.use('/', SESSIONS_ROUTER);
app.use('/', DASHBOARDS_ROUTER);
app.use('/Queue', QUEUE_ROUTER);
app.use('/Users', USERS_ROUTER);
app.use('/Api', API_ROUTER);

Expand Down
47 changes: 27 additions & 20 deletions controllers/Queue.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
const express = require('express');
const router = express.Router();
const { getOneQueue } = require('../models/Queue');

router.post('/saveQueData', function(req, res) {
data = req.body;
var id = data.djID;
var Title = data.Title;
var Artist = data.Artist;
var Album = data.Album;
var Image = data.Image;
var userID = req.session.user.id;
db.none('INSERT INTO QUE (title,artist,album,img,djs_id,fans_id) VALUES ($1,$2,$3,$4,$5,$6)', [Title, Artist, Album, Image, id, userID]).then(function() {
res.send("Song Added!")
router.get('/', getOneQueue, (req, res, next) => {
const queue = req.user;
console.log(queue);
res.send(queue);
});

router.post('/', function(req, res) {
const data = req.body;
const id = data.djID;
const Title = data.Title;
const Artist = data.Artist;
const Album = data.Album;
const Image = data.Image;
const userID = req.session.user.id;

db.none('INSERT INTO QUE (title,artist,album,img,djs_id,fans_id) VALUES ($1,$2,$3,$4,$5,$6)', [Title, Artist, Album, Image, id, userID])
.then(() => {
next();
})
.catch((err) => {
console.log(err)
res.send('Ohh oh something went wrong!')
})

});

router.delete('/deleteQueData', function(req, res) {
var user = req.session.user.id;
var songID = req.body.songID;
router.delete('/', function(req, res) {
const user = req.session.user.id;
const songID = req.body.songID;
console.log(req.body.songID);
db.none('DELETE FROM que WHERE id = $1 AND djs_id = $2', [songID, user]).then(function() {
console.log("Song Deleted");
});
});

router.get('/queData', function(req, res) {
var userID = req.session.user.id;
db.any('SELECT * FROM que WHERE djs_id = $1', [userID])
.then(function(data) {
res.send(data);
})
});
module.exports = router;
11 changes: 9 additions & 2 deletions models/Queue.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
const db = require('../lib/db');

//Get Queue from database that belongs to the logged in User
const getOneQueue = (req, res, next) => {
const userID = req.session.user.id;

db.any('SELECT * FROM que WHERE djs_id = $1', [userID])
.then(function(data) {
res.send(data);
.then((queue) => {
req.user = queue;
next();
})
.catch((err) => {
console.log(err);
res.send('Oh oh something went wrong!')
})
}

// TODO Finish addToQueue route
const addToQueue

module.exports = { getOneQueue };
2 changes: 1 addition & 1 deletion public/scripts/djboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $(document).ready(function() {

var getQue = function() {
$.ajax({
url: 'https://quedj.herokuapp.com/queData/',
url: '/queue',
type: 'GET',
})
.done(function(data) {
Expand Down

0 comments on commit bed683e

Please sign in to comment.