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