From 90d66187d3c0dbe6e7492979be99b57887d3796e Mon Sep 17 00:00:00 2001 From: Taj English Date: Thu, 2 Mar 2017 19:57:15 -0500 Subject: [PATCH] Fixed songs not submitting to database bug --- app.js | 32 -------------------------------- models/Queue.js | 5 ++++- models/User.js | 1 - public/scripts/userboard.js | 2 +- public/scripts/userprofile.js | 7 +++++-- views/profiles/userprofile.html | 7 ++----- 6 files changed, 12 insertions(+), 42 deletions(-) diff --git a/app.js b/app.js index 6f339db..e9f2810 100644 --- a/app.js +++ b/app.js @@ -58,35 +58,3 @@ app.use(DASHBOARDS_ROUTER); app.use('/Users', USERS_ROUTER); app.use('/Queue', QUEUE_ROUTER); app.use('/Api', API_ROUTER); - - -// app.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!") - // }) -// -// }); -// -// app.delete('/deleteQueData', function(req, res) { -// var user = req.session.user.id; -// var 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"); -// }); -// }); -// -// app.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); -// }) -// }); diff --git a/models/Queue.js b/models/Queue.js index f5a4045..35c67e9 100644 --- a/models/Queue.js +++ b/models/Queue.js @@ -18,6 +18,7 @@ const getOneQueue = (req, res, next) => { // Adds songs to users que in database const addToQueue = (req, res, next) => { const data = req.body; + console.log(data); const id = data.djID; const Title = data.Title; const Artist = data.Artist; @@ -25,13 +26,15 @@ const addToQueue = (req, res, next) => { const Image = data.Image; const userID = req.session.user.id; + console.log(req) + 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 with adding your song to the queue!'); + res.write('Ohh oh something went wrong with adding your song to the queue!'); }) } diff --git a/models/User.js b/models/User.js index 1ad9c7b..283bedf 100644 --- a/models/User.js +++ b/models/User.js @@ -93,7 +93,6 @@ const getUserByName = (req, res, next) => { .catch((err) => { res.send('Something went wrong!'); console.log(err); - next(); }) } diff --git a/public/scripts/userboard.js b/public/scripts/userboard.js index 8c764b4..ecf3cca 100644 --- a/public/scripts/userboard.js +++ b/public/scripts/userboard.js @@ -75,7 +75,7 @@ const appendDom = (data) => { let location = value.location; let bio = value.bio; - $('#listDjs').append('
  • image '+name+'

    ' + bio+ '
    ' +'- ' + ''+ location + '' +'

    View') + $('#listDjs').append('
  • image '+name+'

    ' + bio+ '
    ' +'- ' + ''+ location + '' +'

    View') }); } diff --git a/public/scripts/userprofile.js b/public/scripts/userprofile.js index a593ccb..4a3a531 100644 --- a/public/scripts/userprofile.js +++ b/public/scripts/userprofile.js @@ -54,7 +54,10 @@ $(document).ready(() => { appendDom(Title,Artist,Img,Album,Counter); $('#song-num' + Counter).on('click', () => { - const djID = $('#djNum').text(); + + const djID = $('body').data('id'); + console.log(djID) + const songData = { 'djID': djID, 'Title': Title, @@ -64,7 +67,7 @@ $(document).ready(() => { }; $.ajax({ - url: 'https://quedj.herokuapp.com/saveQueData', + url: '/queue', type: 'POST', data: songData }) diff --git a/views/profiles/userprofile.html b/views/profiles/userprofile.html index 9d732a5..968a054 100644 --- a/views/profiles/userprofile.html +++ b/views/profiles/userprofile.html @@ -18,7 +18,7 @@ - +
    @@ -26,15 +26,12 @@
    {{user.first_name}} {{user.last_name}}
    -

    DJ# - {{user.id}}

    Bio - {{user.bio}}

    Location - {{user.location}}

    Up Votes - {{user.upvotes}}

    Down Votes - {{user.downvotes}}

    - +