aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-16 22:31:45 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-16 22:31:45 +0200
commit5c39adb7313e0696aabb4b71196ab7b0b378c359 (patch)
treeac44b67890509338b984f8cbf11660dc77cdd0fd /server/models/user.js
parent089ff2f2046fdbaf9531726eea1f8c6726ebf0c0 (diff)
downloadPeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.gz
PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.zst
PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.zip
Server: add user list sort/pagination
Diffstat (limited to 'server/models/user.js')
-rw-r--r--server/models/user.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/server/models/user.js b/server/models/user.js
index d289da19a..c9c35b3e2 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -1,10 +1,15 @@
1const mongoose = require('mongoose') 1const mongoose = require('mongoose')
2 2
3const customUsersValidators = require('../helpers/custom-validators').users 3const customUsersValidators = require('../helpers/custom-validators').users
4const modelUtils = require('./utils')
4 5
5// --------------------------------------------------------------------------- 6// ---------------------------------------------------------------------------
6 7
7const UserSchema = mongoose.Schema({ 8const UserSchema = mongoose.Schema({
9 createdDate: {
10 type: Date,
11 default: Date.now
12 },
8 password: String, 13 password: String,
9 username: String, 14 username: String,
10 role: String 15 role: String
@@ -19,9 +24,9 @@ UserSchema.methods = {
19} 24}
20 25
21UserSchema.statics = { 26UserSchema.statics = {
22 count: count, 27 countTotal: countTotal,
23 getByUsernameAndPassword: getByUsernameAndPassword, 28 getByUsernameAndPassword: getByUsernameAndPassword,
24 list: list, 29 listForApi: listForApi,
25 loadById: loadById, 30 loadById: loadById,
26 loadByUsername: loadByUsername 31 loadByUsername: loadByUsername
27} 32}
@@ -30,7 +35,7 @@ mongoose.model('User', UserSchema)
30 35
31// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
32 37
33function count (callback) { 38function countTotal (callback) {
34 return this.count(callback) 39 return this.count(callback)
35} 40}
36 41
@@ -38,8 +43,9 @@ function getByUsernameAndPassword (username, password) {
38 return this.findOne({ username: username, password: password }) 43 return this.findOne({ username: username, password: password })
39} 44}
40 45
41function list (callback) { 46function listForApi (start, count, sort, callback) {
42 return this.find(callback) 47 const query = {}
48 return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)
43} 49}
44 50
45function loadById (id, callback) { 51function loadById (id, callback) {