]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account.ts
Fix offset/limit on some SQL queries :facepalm:
[github/Chocobozzz/PeerTube.git] / server / models / account / account.ts
index 54ec7cfccaf31c2d98128d9430d6bd387764a499..3ff59887d4ab93d6d04fddfb1959c23a9d7bbee3 100644 (file)
@@ -157,7 +157,6 @@ export class AccountModel extends Model<AccountModel> {
   static loadLocalByName (name: string) {
     const query = {
       where: {
-        name,
         [ Sequelize.Op.or ]: [
           {
             userId: {
@@ -170,7 +169,41 @@ export class AccountModel extends Model<AccountModel> {
             }
           }
         ]
-      }
+      },
+      include: [
+        {
+          model: ActorModel,
+          required: true,
+          where: {
+            preferredUsername: name
+          }
+        }
+      ]
+    }
+
+    return AccountModel.findOne(query)
+  }
+
+  static loadLocalByNameAndHost (name: string, host: string) {
+    const query = {
+      include: [
+        {
+          model: ActorModel,
+          required: true,
+          where: {
+            preferredUsername: name
+          },
+          include: [
+            {
+              model: ServerModel,
+              required: true,
+              where: {
+                host
+              }
+            }
+          ]
+        }
+      ]
     }
 
     return AccountModel.findOne(query)
@@ -197,7 +230,7 @@ export class AccountModel extends Model<AccountModel> {
     const query = {
       offset: start,
       limit: count,
-      order: getSort(sort),
+      order: getSort(sort)
     }
 
     return AccountModel.findAndCountAll(query)
@@ -213,7 +246,7 @@ export class AccountModel extends Model<AccountModel> {
     const actor = this.Actor.toFormattedJSON()
     const account = {
       id: this.id,
-      displayName: this.name,
+      displayName: this.getDisplayName(),
       description: this.description,
       createdAt: this.createdAt,
       updatedAt: this.updatedAt
@@ -233,4 +266,8 @@ export class AccountModel extends Model<AccountModel> {
   isOwned () {
     return this.Actor.isOwned()
   }
+
+  getDisplayName () {
+    return this.name
+  }
 }