]>
Commit | Line | Data |
---|---|---|
67bf9b96 C |
1 | 'use strict' |
2 | ||
feb4bdfd C |
3 | module.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: { |
4712081f | 33 | countTotal, |
feb4bdfd | 34 | getByIdAndSecret, |
feb4bdfd C |
35 | loadFirstClient |
36 | } | |
37 | } | |
38 | ) | |
39 | ||
40 | return OAuthClient | |
69b0a27c C |
41 | } |
42 | ||
69b0a27c C |
43 | // --------------------------------------------------------------------------- |
44 | ||
4712081f C |
45 | function countTotal (callback) { |
46 | return this.count().asCallback(callback) | |
69b0a27c C |
47 | } |
48 | ||
49 | function loadFirstClient (callback) { | |
feb4bdfd | 50 | return this.findOne().asCallback(callback) |
69b0a27c C |
51 | } |
52 | ||
feb4bdfd C |
53 | function getByIdAndSecret (clientId, clientSecret) { |
54 | const query = { | |
55 | where: { | |
56 | clientId: clientId, | |
57 | clientSecret: clientSecret | |
58 | } | |
59 | } | |
60 | ||
61 | return this.findOne(query) | |
69b0a27c | 62 | } |