aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/oauth-client.ts')
-rw-r--r--server/models/oauth-client.ts55
1 files changed, 41 insertions, 14 deletions
diff --git a/server/models/oauth-client.ts b/server/models/oauth-client.ts
index 3198a85ef..2cefb5cb9 100644
--- a/server/models/oauth-client.ts
+++ b/server/models/oauth-client.ts
@@ -1,5 +1,21 @@
1module.exports = function (sequelize, DataTypes) { 1import * as Sequelize from 'sequelize'
2 const OAuthClient = sequelize.define('OAuthClient', 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, DataTypes) {
18 OAuthClient = sequelize.define('OAuthClient',
3 { 19 {
4 clientId: { 20 clientId: {
5 type: DataTypes.STRING, 21 type: DataTypes.STRING,
@@ -26,29 +42,40 @@ module.exports = function (sequelize, DataTypes) {
26 fields: [ 'clientId', 'clientSecret' ], 42 fields: [ 'clientId', 'clientSecret' ],
27 unique: true 43 unique: true
28 } 44 }
29 ], 45 ]
30 classMethods: {
31 countTotal,
32 getByIdAndSecret,
33 loadFirstClient
34 }
35 } 46 }
36 ) 47 )
37 48
49 const classMethods = [
50 associate,
51
52 countTotal,
53 getByIdAndSecret,
54 loadFirstClient
55 ]
56 addMethodsToModel(OAuthClient, classMethods)
57
38 return OAuthClient 58 return OAuthClient
39} 59}
40 60
41// --------------------------------------------------------------------------- 61// ---------------------------------------------------------------------------
42 62
43function countTotal (callback) { 63function associate (models) {
44 return this.count().asCallback(callback) 64 OAuthClient.hasMany(models.OAuthToken, {
65 foreignKey: 'oAuthClientId',
66 onDelete: 'cascade'
67 })
68}
69
70countTotal = function (callback) {
71 return OAuthClient.count().asCallback(callback)
45} 72}
46 73
47function loadFirstClient (callback) { 74loadFirstClient = function (callback) {
48 return this.findOne().asCallback(callback) 75 return OAuthClient.findOne().asCallback(callback)
49} 76}
50 77
51function getByIdAndSecret (clientId, clientSecret) { 78getByIdAndSecret = function (clientId, clientSecret) {
52 const query = { 79 const query = {
53 where: { 80 where: {
54 clientId: clientId, 81 clientId: clientId,
@@ -56,5 +83,5 @@ function getByIdAndSecret (clientId, clientSecret) {
56 } 83 }
57 } 84 }
58 85
59 return this.findOne(query) 86 return OAuthClient.findOne(query)
60} 87}