]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/oauth-client.js
Update migrations code
[github/Chocobozzz/PeerTube.git] / server / models / oauth-client.js
CommitLineData
feb4bdfd
C
1module.exports = function (sequelize, DataTypes) {
2 const OAuthClient = sequelize.define('OAuthClient',
3 {
4 clientId: {
5 type: DataTypes.STRING
6 },
7 clientSecret: {
8 type: DataTypes.STRING
9 },
10 grants: {
11 type: DataTypes.ARRAY(DataTypes.STRING)
12 },
13 redirectUris: {
14 type: DataTypes.ARRAY(DataTypes.STRING)
15 }
16 },
17 {
18 classMethods: {
19 associate,
20
21 getByIdAndSecret,
22 list,
23 loadFirstClient
24 }
25 }
26 )
27
28 return OAuthClient
69b0a27c
C
29}
30
feb4bdfd
C
31// TODO: validation
32// OAuthClientSchema.path('clientSecret').required(true)
69b0a27c
C
33
34// ---------------------------------------------------------------------------
35
feb4bdfd
C
36function associate (models) {
37 this.hasMany(models.OAuthToken, {
38 foreignKey: {
39 name: 'oAuthClientId',
40 allowNull: false
41 },
42 onDelete: 'cascade'
43 })
44}
45
69b0a27c 46function list (callback) {
feb4bdfd 47 return this.findAll().asCallback(callback)
69b0a27c
C
48}
49
50function loadFirstClient (callback) {
feb4bdfd 51 return this.findOne().asCallback(callback)
69b0a27c
C
52}
53
feb4bdfd
C
54function getByIdAndSecret (clientId, clientSecret) {
55 const query = {
56 where: {
57 clientId: clientId,
58 clientSecret: clientSecret
59 }
60 }
61
62 return this.findOne(query)
69b0a27c 63}