From bb67bb169782857116a587675a99a760e24bc506 Mon Sep 17 00:00:00 2001 From: Gregorio Date: Sun, 3 Mar 2019 17:58:09 +0100 Subject: [PATCH] jaja --- node-entry.js | 13 ++++++++++--- src/App.js | 7 +------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/node-entry.js b/node-entry.js index 87c7fbe..fe58d25 100644 --- a/node-entry.js +++ b/node-entry.js @@ -79,7 +79,14 @@ low(new FileAsync(__dirname + '/db.json')) // production 'Access-Control-Allow-Origin': '*' }); const videos = db.get('videos'); - req.query.id ? res.send(videos.getById(req.query.id).value()) : res.send(videos.value()) + if (req.query.prevId){ + let tmp=videos.map(el=>el.id.reason.map(el=>el.reason.map(el2=>{ + if(el2.prevId===req.query.prevId){ + return {...el2, 'id':this.id} + } + },el))); + res.send(tmp)} + else{res.send(videos)} }); // POST /videotrack @@ -118,7 +125,7 @@ low(new FileAsync(__dirname + '/db.json')) // production row .update('timesWatched', (n) => ++n) .update('lastWatched', () => new Date().toISOString()) - .update('reason', (n) => setReason(req.body.reason, n, req.body.id)) + .update('reason', (n) => setReason(req.body.reason, n, req.body.prevId)) .write() .then(output => res.send(200, output)) } else { @@ -126,7 +133,7 @@ low(new FileAsync(__dirname + '/db.json')) // production "id": req.body.id.toString(), "timesWatched": 1, "lastWatched": new Date().toISOString(), - "reason": setReason(req.body.reason,[],req.body.id) + "reason": setReason(req.body.reason,[],req.body.prevId) } videos.push(newRow).last().write().then(output => res.send(200, output)) } diff --git a/src/App.js b/src/App.js index ec62078..f0e7998 100644 --- a/src/App.js +++ b/src/App.js @@ -34,19 +34,14 @@ class App extends React.Component { exact: true, strict: false }); - if (prevState.videoId !== null) { if (idMatch && idMatch.params.id !== prevState.videoId) { localStorage.setItem('prevId', prevState.videoId) localStorage.setItem('lastId', idMatch.params.id) return { videoId: idMatch.params.id }; } else { - if (idMatch && idMatch.params.id !== prevState.videoId) { - localStorage.setItem('lastId', idMatch.params.id) - return { videoId: idMatch.params.id }; - } return null; - } + } }