-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
3 changed files
with
45 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const videos = require('../../services/videos'); | ||
|
||
/* GET videos */ | ||
router.get('/', async function(req, res, next) { | ||
try { | ||
res.json(await videos.getMultiple(req.query.userid, req.query.page)); | ||
} catch (err) { | ||
console.error(`Error while getting videos `, err.message); | ||
next(err); | ||
} | ||
}); | ||
|
||
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const db = require('./db'); | ||
const helper = require('../helper'); | ||
const config = require('../config'); | ||
|
||
async function getMultiple(userid, page = 1){ | ||
const offset = helper.getOffset(page, config.listPerPage); | ||
const rows = await db.query( | ||
`SELECT videoId, youtubeId, soundcloudId, vimeoId, bandcampId, isFlagged, tags, title | ||
FROM video WHERE videoId IN ( | ||
SELECT videoId FROM user_video WHERE userId = ? | ||
) ORDER BY videoId LIMIT ?,?`, | ||
[userid, offset, config.listPerPage] | ||
); | ||
const data = helper.emptyOrRows(rows); | ||
const meta = {page}; | ||
|
||
return { | ||
data, | ||
meta | ||
} | ||
} | ||
|
||
module.exports = { | ||
getMultiple | ||
} |