aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth/oauth-client.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 09:45:46 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 09:45:46 +0200
commit74889a71fe687dda74f2a687653122327807af36 (patch)
treee938e8b6401b74fbec80513a877d9967f2c0dbcd /server/models/oauth/oauth-client.ts
parent15a302943d84bc0978b84fe33110c4daa451d311 (diff)
downloadPeerTube-74889a71fe687dda74f2a687653122327807af36.tar.gz
PeerTube-74889a71fe687dda74f2a687653122327807af36.tar.zst
PeerTube-74889a71fe687dda74f2a687653122327807af36.zip
Reorganize model files
Diffstat (limited to 'server/models/oauth/oauth-client.ts')
-rw-r--r--server/models/oauth/oauth-client.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/server/models/oauth/oauth-client.ts b/server/models/oauth/oauth-client.ts
new file mode 100644
index 000000000..fbc2a3393
--- /dev/null
+++ b/server/models/oauth/oauth-client.ts
@@ -0,0 +1,87 @@
1import * as Sequelize from 'sequelize'
2
3import { addMethodsToModel } from '../utils'
4import {
5 OAuthClientClass,
6 OAuthClientInstance,
7 OAuthClientAttributes,
8
9 OAuthClientMethods
10} from './oauth-client-interface'
11
12let OAuthClient: Sequelize.Model<OAuthClientInstance, OAuthClientAttributes>
13let countTotal: OAuthClientMethods.CountTotal
14let loadFirstClient: OAuthClientMethods.LoadFirstClient
15let getByIdAndSecret: OAuthClientMethods.GetByIdAndSecret
16
17export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
18 OAuthClient = sequelize.define<OAuthClientInstance, OAuthClientAttributes>('OAuthClient',
19 {
20 clientId: {
21 type: DataTypes.STRING,
22 allowNull: false
23 },
24 clientSecret: {
25 type: DataTypes.STRING,
26 allowNull: false
27 },
28 grants: {
29 type: DataTypes.ARRAY(DataTypes.STRING)
30 },
31 redirectUris: {
32 type: DataTypes.ARRAY(DataTypes.STRING)
33 }
34 },
35 {
36 indexes: [
37 {
38 fields: [ 'clientId' ],
39 unique: true
40 },
41 {
42 fields: [ 'clientId', 'clientSecret' ],
43 unique: true
44 }
45 ]
46 }
47 )
48
49 const classMethods = [
50 associate,
51
52 countTotal,
53 getByIdAndSecret,
54 loadFirstClient
55 ]
56 addMethodsToModel(OAuthClient, classMethods)
57
58 return OAuthClient
59}
60
61// ---------------------------------------------------------------------------
62
63function associate (models) {
64 OAuthClient.hasMany(models.OAuthToken, {
65 foreignKey: 'oAuthClientId',
66 onDelete: 'cascade'
67 })
68}
69
70countTotal = function (callback: OAuthClientMethods.CountTotalCallback) {
71 return OAuthClient.count().asCallback(callback)
72}
73
74loadFirstClient = function (callback: OAuthClientMethods.LoadFirstClientCallback) {
75 return OAuthClient.findOne().asCallback(callback)
76}
77
78getByIdAndSecret = function (clientId: string, clientSecret: string) {
79 const query = {
80 where: {
81 clientId: clientId,
82 clientSecret: clientSecret
83 }
84 }
85
86 return OAuthClient.findOne(query)
87}