]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/user.js
Server: add user list sort/pagination
[github/Chocobozzz/PeerTube.git] / server / models / user.js
index 351ffef86244900e2484a1ec5b7ea3f459bc942c..c9c35b3e2dffc0c06cbe6d35f379135998aae583 100644 (file)
@@ -1,10 +1,15 @@
 const mongoose = require('mongoose')
 
 const customUsersValidators = require('../helpers/custom-validators').users
+const modelUtils = require('./utils')
 
 // ---------------------------------------------------------------------------
 
 const UserSchema = mongoose.Schema({
+  createdDate: {
+    type: Date,
+    default: Date.now
+  },
   password: String,
   username: String,
   role: String
@@ -19,8 +24,9 @@ UserSchema.methods = {
 }
 
 UserSchema.statics = {
+  countTotal: countTotal,
   getByUsernameAndPassword: getByUsernameAndPassword,
-  list: list,
+  listForApi: listForApi,
   loadById: loadById,
   loadByUsername: loadByUsername
 }
@@ -29,12 +35,17 @@ mongoose.model('User', UserSchema)
 
 // ---------------------------------------------------------------------------
 
+function countTotal (callback) {
+  return this.count(callback)
+}
+
 function getByUsernameAndPassword (username, password) {
   return this.findOne({ username: username, password: password })
 }
 
-function list (callback) {
-  return this.find(callback)
+function listForApi (start, count, sort, callback) {
+  const query = {}
+  return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)
 }
 
 function loadById (id, callback) {