diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-16 09:45:46 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-16 09:45:46 +0200 |
commit | 74889a71fe687dda74f2a687653122327807af36 (patch) | |
tree | e938e8b6401b74fbec80513a877d9967f2c0dbcd /server/models/oauth-client.ts | |
parent | 15a302943d84bc0978b84fe33110c4daa451d311 (diff) | |
download | PeerTube-74889a71fe687dda74f2a687653122327807af36.tar.gz PeerTube-74889a71fe687dda74f2a687653122327807af36.tar.zst PeerTube-74889a71fe687dda74f2a687653122327807af36.zip |
Reorganize model files
Diffstat (limited to 'server/models/oauth-client.ts')
-rw-r--r-- | server/models/oauth-client.ts | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/server/models/oauth-client.ts b/server/models/oauth-client.ts deleted file mode 100644 index a5438f45a..000000000 --- a/server/models/oauth-client.ts +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | import { addMethodsToModel } from './utils' | ||
4 | import { | ||
5 | OAuthClientClass, | ||
6 | OAuthClientInstance, | ||
7 | OAuthClientAttributes, | ||
8 | |||
9 | OAuthClientMethods | ||
10 | } from './oauth-client-interface' | ||
11 | |||
12 | let OAuthClient: Sequelize.Model<OAuthClientInstance, OAuthClientAttributes> | ||
13 | let countTotal: OAuthClientMethods.CountTotal | ||
14 | let loadFirstClient: OAuthClientMethods.LoadFirstClient | ||
15 | let getByIdAndSecret: OAuthClientMethods.GetByIdAndSecret | ||
16 | |||
17 | export 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 | |||
63 | function associate (models) { | ||
64 | OAuthClient.hasMany(models.OAuthToken, { | ||
65 | foreignKey: 'oAuthClientId', | ||
66 | onDelete: 'cascade' | ||
67 | }) | ||
68 | } | ||
69 | |||
70 | countTotal = function (callback: OAuthClientMethods.CountTotalCallback) { | ||
71 | return OAuthClient.count().asCallback(callback) | ||
72 | } | ||
73 | |||
74 | loadFirstClient = function (callback: OAuthClientMethods.LoadFirstClientCallback) { | ||
75 | return OAuthClient.findOne().asCallback(callback) | ||
76 | } | ||
77 | |||
78 | getByIdAndSecret = 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 | } | ||