1
0
Fork 0
peertube/server/models/oauth-client.js

65 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-12-28 14:49:23 +00:00
'use strict'
2016-12-11 20:50:51 +00:00
module.exports = function (sequelize, DataTypes) {
const OAuthClient = sequelize.define('OAuthClient',
{
clientId: {
2016-12-28 14:49:23 +00:00
type: DataTypes.STRING,
allowNull: false
2016-12-11 20:50:51 +00:00
},
clientSecret: {
2016-12-28 14:49:23 +00:00
type: DataTypes.STRING,
allowNull: false
2016-12-11 20:50:51 +00:00
},
grants: {
type: DataTypes.ARRAY(DataTypes.STRING)
},
redirectUris: {
type: DataTypes.ARRAY(DataTypes.STRING)
}
},
{
classMethods: {
associate,
getByIdAndSecret,
list,
loadFirstClient
}
}
)
return OAuthClient
}
// ---------------------------------------------------------------------------
2016-12-11 20:50:51 +00:00
function associate (models) {
this.hasMany(models.OAuthToken, {
foreignKey: {
name: 'oAuthClientId',
allowNull: false
},
onDelete: 'cascade'
})
}
function list (callback) {
2016-12-11 20:50:51 +00:00
return this.findAll().asCallback(callback)
}
function loadFirstClient (callback) {
2016-12-11 20:50:51 +00:00
return this.findOne().asCallback(callback)
}
2016-12-11 20:50:51 +00:00
function getByIdAndSecret (clientId, clientSecret) {
const query = {
where: {
clientId: clientId,
clientSecret: clientSecret
}
}
return this.findOne(query)
}