]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/oauth-client.js
Server: add updatedAt attribute to videos
[github/Chocobozzz/PeerTube.git] / server / models / oauth-client.js
index 15118591a72350e08edc47958d98f8afbba2fdb2..021a3400752d50e6ab427852b21c294676ac7da8 100644 (file)
@@ -1,11 +1,15 @@
+'use strict'
+
 module.exports = function (sequelize, DataTypes) {
   const OAuthClient = sequelize.define('OAuthClient',
     {
       clientId: {
-        type: DataTypes.STRING
+        type: DataTypes.STRING,
+        allowNull: false
       },
       clientSecret: {
-        type: DataTypes.STRING
+        type: DataTypes.STRING,
+        allowNull: false
       },
       grants: {
         type: DataTypes.ARRAY(DataTypes.STRING)
@@ -15,11 +19,19 @@ module.exports = function (sequelize, DataTypes) {
       }
     },
     {
+      indexes: [
+        {
+          fields: [ 'clientId' ],
+          unique: true
+        },
+        {
+          fields: [ 'clientId', 'clientSecret' ],
+          unique: true
+        }
+      ],
       classMethods: {
-        associate,
-
+        countTotal,
         getByIdAndSecret,
-        list,
         loadFirstClient
       }
     }
@@ -28,23 +40,10 @@ module.exports = function (sequelize, DataTypes) {
   return OAuthClient
 }
 
-// TODO: validation
-// OAuthClientSchema.path('clientSecret').required(true)
-
 // ---------------------------------------------------------------------------
 
-function associate (models) {
-  this.hasMany(models.OAuthToken, {
-    foreignKey: {
-      name: 'oAuthClientId',
-      allowNull: false
-    },
-    onDelete: 'cascade'
-  })
-}
-
-function list (callback) {
-  return this.findAll().asCallback(callback)
+function countTotal (callback) {
+  return this.count().asCallback(callback)
 }
 
 function loadFirstClient (callback) {