This commit is contained in:
Gregorio
2019-03-03 17:58:09 +01:00
parent 8af517b965
commit bb67bb1697
2 changed files with 11 additions and 9 deletions
+10 -3
View File
@@ -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))
}