mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-24 17:59:06 +02:00
Update:Get all users api endpoint to include latest session, display device info on users table #724
This commit is contained in:
parent
1668153acd
commit
bb9013541b
3 changed files with 30 additions and 8 deletions
|
@ -8,12 +8,24 @@ const { getId, toNumber } = require('../utils/index')
|
|||
class UserController {
|
||||
constructor() { }
|
||||
|
||||
findAll(req, res) {
|
||||
async findAll(req, res) {
|
||||
if (!req.user.isAdminOrUp) return res.sendStatus(403)
|
||||
const hideRootToken = !req.user.isRoot
|
||||
|
||||
const includes = (req.query.include || '').split(',').map(i => i.trim())
|
||||
|
||||
// Minimal toJSONForBrowser does not include mediaProgress and bookmarks
|
||||
const users = this.db.users.map(u => u.toJSONForBrowser(hideRootToken, true))
|
||||
|
||||
if (includes.includes('latestSession')) {
|
||||
for (const user of users) {
|
||||
const userSessions = await this.db.selectUserSessions(user.id)
|
||||
user.latestSession = userSessions.sort((a, b) => b.updatedAt - a.updatedAt).shift() || null
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
// Minimal toJSONForBrowser does not include mediaProgress and bookmarks
|
||||
users: this.db.users.map(u => u.toJSONForBrowser(hideRootToken, true))
|
||||
users
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue