aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes/admin/userGET.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-01-20 00:43:03 +0900
committerPitu <[email protected]>2021-01-20 00:43:03 +0900
commitbf0b0f64bf84f2e2b3073b1b351681508bc1e625 (patch)
treeedbe1cb93190e25809807587537ecdb4ab909684 /src/api/routes/admin/userGET.js
parentMerge pull request #253 from Zephyrrus/fix/fetching_restricted_data_on_public... (diff)
downloadhost.fuwn.me-bf0b0f64bf84f2e2b3073b1b351681508bc1e625.tar.xz
host.fuwn.me-bf0b0f64bf84f2e2b3073b1b351681508bc1e625.zip
feat: add pagination to user files in admin view
Diffstat (limited to 'src/api/routes/admin/userGET.js')
-rw-r--r--src/api/routes/admin/userGET.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/api/routes/admin/userGET.js b/src/api/routes/admin/userGET.js
index 48c6e9b..430dfd7 100644
--- a/src/api/routes/admin/userGET.js
+++ b/src/api/routes/admin/userGET.js
@@ -15,10 +15,27 @@ class usersGET extends Route {
.select('id', 'username', 'enabled', 'createdAt', 'editedAt', 'apiKeyEditedAt', 'isAdmin')
.where({ id })
.first();
- const files = await db.table('files')
+
+ let count = 0;
+ let files = db.table('files')
.where({ userId: user.id })
.orderBy('id', 'desc');
+ const { page, limit = 100 } = req.query;
+ if (page && page >= 0) {
+ files = await files.offset((page - 1) * limit).limit(limit);
+
+ const dbRes = await db.table('files')
+ .count('* as count')
+ .where({ userId: user.id })
+ .first();
+
+ count = dbRes.count;
+ } else {
+ files = await files; // execute the query
+ count = files.length;
+ }
+
for (let file of files) {
file = Util.constructFilePublicLink(file);
}
@@ -26,7 +43,8 @@ class usersGET extends Route {
return res.json({
message: 'Successfully retrieved user',
user,
- files
+ files,
+ count
});
} catch (error) {
return super.error(res, error);