-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