const modelUtils = require('./utils')
const peertubeCrypto = require('../helpers/peertube-crypto')
+const OAuthToken = mongoose.model('OAuthToken')
+
// ---------------------------------------------------------------------------
const UserSchema = mongoose.Schema({
UserSchema.path('role').validate(customUsersValidators.isUserRoleValid)
UserSchema.methods = {
- isPasswordMatch: isPasswordMatch,
- toFormatedJSON: toFormatedJSON
+ isPasswordMatch,
+ toFormatedJSON
}
UserSchema.statics = {
- countTotal: countTotal,
- getByUsername: getByUsername,
- list: list,
- listForApi: listForApi,
- loadById: loadById,
- loadByUsername: loadByUsername
+ countTotal,
+ getByUsername,
+ list,
+ listForApi,
+ loadById,
+ loadByUsername
}
UserSchema.pre('save', function (next) {
})
})
+UserSchema.pre('remove', function (next) {
+ const user = this
+
+ OAuthToken.removeByUserId(user._id, next)
+})
+
mongoose.model('User', UserSchema)
// ------------------------------ METHODS ------------------------------