Merge pull request #54 from KevinMidboe/api_save-user-w-request
Api save user w request
This commit is contained in:
@@ -46,6 +46,7 @@ export function fetchJSON(url, method, data) {
|
|||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'authorization': getCookie('token'),
|
'authorization': getCookie('token'),
|
||||||
|
'loggedinuser': getCookie('loggedInUser'),
|
||||||
}),
|
}),
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
}).then(checkStatus).then(parseJSON);
|
}).then(checkStatus).then(parseJSON);
|
||||||
|
|||||||
@@ -110,17 +110,14 @@ class RequestRepository {
|
|||||||
* @param {identifier, type} the id of the media object and type of media must be defined
|
* @param {identifier, type} the id of the media object and type of media must be defined
|
||||||
* @returns {Promise} If nothing has gone wrong.
|
* @returns {Promise} If nothing has gone wrong.
|
||||||
*/
|
*/
|
||||||
sendRequest(identifier, type, ip, user_agent) {
|
sendRequest(identifier, type, ip, user_agent, user) {
|
||||||
// TODO add to DB so can have a admin page
|
|
||||||
// TODO try a cache hit on the movie item
|
|
||||||
|
|
||||||
tmdb.lookup(identifier, type).then(movie => {
|
tmdb.lookup(identifier, type).then(movie => {
|
||||||
|
|
||||||
|
if (user === 'false')
|
||||||
|
user = 'NULL';
|
||||||
|
console.log(user)
|
||||||
// Add request to database
|
// Add request to database
|
||||||
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, 'NULL', ip, user_agent, movie.type])
|
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, user, ip, user_agent, movie.type])
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
// create reusable transporter object using the default SMTP transport
|
// create reusable transporter object using the default SMTP transport
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ function submitRequestController(req, res) {
|
|||||||
// This is the id that is the param of the url
|
// This is the id that is the param of the url
|
||||||
const id = req.params.mediaId;
|
const id = req.params.mediaId;
|
||||||
const type = req.query.type;
|
const type = req.query.type;
|
||||||
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||||
var user_agent = req.headers['user-agent']
|
const user_agent = req.headers['user-agent']
|
||||||
|
const user = req.headers.loggedinuser;
|
||||||
|
|
||||||
requestRepository.sendRequest(id, type, ip, user_agent)
|
requestRepository.sendRequest(id, type, ip, user_agent, user)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.send({ success: true, message: 'Media item sucessfully requested!' });
|
res.send({ success: true, message: 'Media item sucessfully requested!' });
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user