]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/user.js
Server: Remove unused console log
[github/Chocobozzz/PeerTube.git] / server / models / user.js
index e76aab2ce5ad25d1459b90c9a7423cce8acef7d7..a19de7072cd77ae5e881297e775f25c829ab45aa 100644 (file)
@@ -4,6 +4,8 @@ const customUsersValidators = require('../helpers/custom-validators').users
 const modelUtils = require('./utils')
 const peertubeCrypto = require('../helpers/peertube-crypto')
 
+const OAuthToken = mongoose.model('OAuthToken')
+
 // ---------------------------------------------------------------------------
 
 const UserSchema = mongoose.Schema({
@@ -21,16 +23,17 @@ UserSchema.path('username').required(customUsersValidators.isUserUsernameValid)
 UserSchema.path('role').validate(customUsersValidators.isUserRoleValid)
 
 UserSchema.methods = {
-  isPasswordMatch: isPasswordMatch,
-  toFormatedJSON: toFormatedJSON
+  isPasswordMatch,
+  toFormatedJSON
 }
 
 UserSchema.statics = {
-  countTotal: countTotal,
-  getByUsername: getByUsername,
-  listForApi: listForApi,
-  loadById: loadById,
-  loadByUsername: loadByUsername
+  countTotal,
+  getByUsername,
+  list,
+  listForApi,
+  loadById,
+  loadByUsername
 }
 
 UserSchema.pre('save', function (next) {
@@ -45,6 +48,12 @@ UserSchema.pre('save', function (next) {
   })
 })
 
+UserSchema.pre('remove', function (next) {
+  const user = this
+
+  OAuthToken.removeByUserId(user._id, next)
+})
+
 mongoose.model('User', UserSchema)
 
 // ------------------------------ METHODS ------------------------------
@@ -57,7 +66,8 @@ function toFormatedJSON () {
   return {
     id: this._id,
     username: this.username,
-    role: this.role
+    role: this.role,
+    createdDate: this.createdDate
   }
 }
 // ------------------------------ STATICS ------------------------------
@@ -70,6 +80,10 @@ function getByUsername (username) {
   return this.findOne({ username: username })
 }
 
+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)