a1aefa985283ad279a6e925e3a918784b4c8e244
[oweals/peertube.git] / server / models / oauth-client.js
1 const mongoose = require('mongoose')
2
3 // ---------------------------------------------------------------------------
4
5 const OAuthClientSchema = mongoose.Schema({
6   clientSecret: String,
7   grants: Array,
8   redirectUris: Array
9 })
10
11 OAuthClientSchema.path('clientSecret').required(true)
12
13 OAuthClientSchema.statics = {
14   getByIdAndSecret,
15   list,
16   loadFirstClient
17 }
18
19 mongoose.model('OAuthClient', OAuthClientSchema)
20
21 // ---------------------------------------------------------------------------
22
23 function list (callback) {
24   return this.find(callback)
25 }
26
27 function loadFirstClient (callback) {
28   return this.findOne({}, callback)
29 }
30
31 function getByIdAndSecret (id, clientSecret) {
32   return this.findOne({ _id: id, clientSecret: clientSecret }).exec()
33 }