-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3aa26b
commit bed683e
Showing
4 changed files
with
39 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters