+'use strict'
+
module.exports = function (sequelize, DataTypes) {
const OAuthClient = sequelize.define('OAuthClient',
{
clientId: {
- type: DataTypes.STRING
+ type: DataTypes.STRING,
+ allowNull: false
},
clientSecret: {
- type: DataTypes.STRING
+ type: DataTypes.STRING,
+ allowNull: false
},
grants: {
type: DataTypes.ARRAY(DataTypes.STRING)
}
},
{
+ indexes: [
+ {
+ fields: [ 'clientId' ],
+ unique: true
+ },
+ {
+ fields: [ 'clientId', 'clientSecret' ],
+ unique: true
+ }
+ ],
classMethods: {
- associate,
-
+ countTotal,
getByIdAndSecret,
- list,
loadFirstClient
}
}
return OAuthClient
}
-// TODO: validation
-// OAuthClientSchema.path('clientSecret').required(true)
-
// ---------------------------------------------------------------------------
-function associate (models) {
- this.hasMany(models.OAuthToken, {
- foreignKey: {
- name: 'oAuthClientId',
- allowNull: false
- },
- onDelete: 'cascade'
- })
-}
-
-function list (callback) {
- return this.findAll().asCallback(callback)
+function countTotal (callback) {
+ return this.count().asCallback(callback)
}
function loadFirstClient (callback) {