2016-12-28 09:49:23 -05:00
|
|
|
'use strict'
|
|
|
|
|
2016-12-11 15:50:51 -05:00
|
|
|
module.exports = function (sequelize, DataTypes) {
|
|
|
|
const OAuthClient = sequelize.define('OAuthClient',
|
|
|
|
{
|
|
|
|
clientId: {
|
2016-12-28 09:49:23 -05:00
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false
|
2016-12-11 15:50:51 -05:00
|
|
|
},
|
|
|
|
clientSecret: {
|
2016-12-28 09:49:23 -05:00
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false
|
2016-12-11 15:50:51 -05:00
|
|
|
},
|
|
|
|
grants: {
|
|
|
|
type: DataTypes.ARRAY(DataTypes.STRING)
|
|
|
|
},
|
|
|
|
redirectUris: {
|
|
|
|
type: DataTypes.ARRAY(DataTypes.STRING)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2016-12-29 03:33:28 -05:00
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'clientId' ],
|
|
|
|
unique: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'clientId', 'clientSecret' ],
|
|
|
|
unique: true
|
|
|
|
}
|
|
|
|
],
|
2016-12-11 15:50:51 -05:00
|
|
|
classMethods: {
|
2016-12-29 04:33:36 -05:00
|
|
|
countTotal,
|
2016-12-11 15:50:51 -05:00
|
|
|
getByIdAndSecret,
|
|
|
|
loadFirstClient
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return OAuthClient
|
2016-07-01 10:03:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2016-12-29 04:33:36 -05:00
|
|
|
function countTotal (callback) {
|
|
|
|
return this.count().asCallback(callback)
|
2016-07-01 10:03:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadFirstClient (callback) {
|
2016-12-11 15:50:51 -05:00
|
|
|
return this.findOne().asCallback(callback)
|
2016-07-01 10:03:53 -04:00
|
|
|
}
|
|
|
|
|
2016-12-11 15:50:51 -05:00
|
|
|
function getByIdAndSecret (clientId, clientSecret) {
|
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
clientId: clientId,
|
|
|
|
clientSecret: clientSecret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.findOne(query)
|
2016-07-01 10:03:53 -04:00
|
|
|
}
|