X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fmodels%2Foauth-client.js;h=021a3400752d50e6ab427852b21c294676ac7da8;hb=d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73;hp=45834c5a5374328d238f20a78f68a534d36e9cfa;hpb=32bb41560279dd0c75d0461f081873483e3aaed9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/oauth-client.js b/server/models/oauth-client.js index 45834c5a5..021a34007 100644 --- a/server/models/oauth-client.js +++ b/server/models/oauth-client.js @@ -1,33 +1,62 @@ -const mongoose = require('mongoose') - -// --------------------------------------------------------------------------- - -const OAuthClientSchema = mongoose.Schema({ - clientSecret: String, - grants: Array, - redirectUris: Array -}) - -OAuthClientSchema.path('clientSecret').required(true) - -OAuthClientSchema.statics = { - getByIdAndSecret: getByIdAndSecret, - list: list, - loadFirstClient: loadFirstClient +'use strict' + +module.exports = function (sequelize, DataTypes) { + const OAuthClient = sequelize.define('OAuthClient', + { + clientId: { + type: DataTypes.STRING, + allowNull: false + }, + clientSecret: { + type: DataTypes.STRING, + allowNull: false + }, + grants: { + type: DataTypes.ARRAY(DataTypes.STRING) + }, + redirectUris: { + type: DataTypes.ARRAY(DataTypes.STRING) + } + }, + { + indexes: [ + { + fields: [ 'clientId' ], + unique: true + }, + { + fields: [ 'clientId', 'clientSecret' ], + unique: true + } + ], + classMethods: { + countTotal, + getByIdAndSecret, + loadFirstClient + } + } + ) + + return OAuthClient } -mongoose.model('OAuthClient', OAuthClientSchema) - // --------------------------------------------------------------------------- -function list (callback) { - return this.find(callback) +function countTotal (callback) { + return this.count().asCallback(callback) } function loadFirstClient (callback) { - return this.findOne({}, callback) + return this.findOne().asCallback(callback) } -function getByIdAndSecret (id, clientSecret) { - return this.findOne({ _id: id, clientSecret: clientSecret }).exec() +function getByIdAndSecret (clientId, clientSecret) { + const query = { + where: { + clientId: clientId, + clientSecret: clientSecret + } + } + + return this.findOne(query) }