1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

OAuth/User models refractoring -> use mongoose api

This commit is contained in:
Chocobozzz 2016-07-01 16:03:53 +02:00
parent a3ee6fa22d
commit 69b0a27cbb
14 changed files with 217 additions and 156 deletions

View file

@ -0,0 +1,33 @@
const mongoose = require('mongoose')
// ---------------------------------------------------------------------------
const OAuthClientSchema = mongoose.Schema({
clientSecret: String,
grants: Array,
redirectUris: Array
})
OAuthClientSchema.path('clientSecret').required(true)
OAuthClientSchema.statics = {
list: list,
loadByIdAndSecret: loadByIdAndSecret,
loadFirstClient: loadFirstClient
}
mongoose.model('OAuthClient', OAuthClientSchema)
// ---------------------------------------------------------------------------
function list (callback) {
return this.find(callback)
}
function loadFirstClient (callback) {
return this.findOne({}, callback)
}
function loadByIdAndSecret (id, clientSecret) {
return this.findOne({ _id: id, clientSecret: clientSecret })
}