aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-client.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models/oauth-client.ts
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/models/oauth-client.ts')
-rw-r--r--server/models/oauth-client.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/server/models/oauth-client.ts b/server/models/oauth-client.ts
new file mode 100644
index 000000000..3198a85ef
--- /dev/null
+++ b/server/models/oauth-client.ts
@@ -0,0 +1,60 @@
1module.exports = function (sequelize, DataTypes) {
2 const OAuthClient = sequelize.define('OAuthClient',
3 {
4 clientId: {
5 type: DataTypes.STRING,
6 allowNull: false
7 },
8 clientSecret: {
9 type: DataTypes.STRING,
10 allowNull: false
11 },
12 grants: {
13 type: DataTypes.ARRAY(DataTypes.STRING)
14 },
15 redirectUris: {
16 type: DataTypes.ARRAY(DataTypes.STRING)
17 }
18 },
19 {
20 indexes: [
21 {
22 fields: [ 'clientId' ],
23 unique: true
24 },
25 {
26 fields: [ 'clientId', 'clientSecret' ],
27 unique: true
28 }
29 ],
30 classMethods: {
31 countTotal,
32 getByIdAndSecret,
33 loadFirstClient
34 }
35 }
36 )
37
38 return OAuthClient
39}
40
41// ---------------------------------------------------------------------------
42
43function countTotal (callback) {
44 return this.count().asCallback(callback)
45}
46
47function loadFirstClient (callback) {
48 return this.findOne().asCallback(callback)
49}
50
51function getByIdAndSecret (clientId, clientSecret) {
52 const query = {
53 where: {
54 clientId: clientId,
55 clientSecret: clientSecret
56 }
57 }
58
59 return this.findOne(query)
60}