浏览代码

Show org name when backer is an org

Riccardo Balbo 4 年之前
父节点
当前提交
8c2ca61f9d
共有 1 个文件被更改,包括 49 次插入46 次删除
  1. 49 46
      static/js/OpenCollectiveUtils.js

+ 49 - 46
static/js/OpenCollectiveUtils.js

@@ -3,39 +3,34 @@ import CacheUtils from "./CacheUtils.js"
 const OPEN_COLLECTIVE_ENDPOINT= ()=>"https://api.opencollective.com/graphql/v2";
 const OPEN_COLLECTIVE_BACKER_QUERY = (org) => `
 query collective ($offset: Int, $limit: Int){
-    collective(slug: "${org}") {
-      name
-      backers: members(role: BACKER, offset: $offset, limit: $limit) {
-        limit
-        totalCount
-        nodes {
-          publicMessage
-          totalDonations {
-            value
-            currency
-            valueInCents
+  collective(slug: "${org}") {
+    name
+    backers: members(role: BACKER, offset: $offset, limit: $limit) {
+      limit
+      totalCount
+      nodes {
+        publicMessage
+        totalDonations {
+          value
+          currency
+          valueInCents
+        }
+        account {
+          slug
+          type
+          name
+          imageUrl
+          website
+          twitterHandle
+          ... on Individual {
+            email
           }
-          account {
-            slug
-            type
-          
-            
-            ... on Individual {
-              email
-              name
-              website
-              imageUrl
-            }
-            ... on Organization {
-              admins: members(role: ADMIN) {
-                nodes {
-                  account {
-                    ... on Individual {
-                      email
-                      name
-                      website
-                      imageUrl
-                    }
+          ... on Organization {
+            admins: members(role: ADMIN) {
+              nodes {
+                account {
+                  ... on Individual {
+                    email
                   }
                 }
               }
@@ -45,6 +40,8 @@ query collective ($offset: Int, $limit: Int){
       }
     }
   }
+}
+
   `;
 export default class OpenCollectiveUtils {
   static async    getBackers(collective) {
@@ -94,21 +91,27 @@ export default class OpenCollectiveUtils {
       let account = backer.account;
       entry.accountUrl = "https://opencollective.com/" + account.slug;
 
-      const subAccounts = [];
-      if (account.type == "ORGANIZATION") {
-        account.admins.nodes.forEach(admin => subAccounts.push(admin.account));
-      } else {
-        subAccounts.push(account);
-      }
-
-      subAccounts.forEach(account => {
-        const subEntry = { ...entry };
-        subEntry.name = account.name;
-        subEntry.website = account.website;
-        subEntry.avatar = account.imageUrl;
-        backers.push(subEntry);
-      });
+      // const subAccounts = [];
+      // if (account.type == "ORGANIZATION") {
+      //   account.admins.nodes.forEach(admin => subAccounts.push(admin.account));
+      // } else {
+      //   subAccounts.push(account);
+      // }
 
+      // subAccounts.forEach(account => {
+        // const subEntry = { ...entry };
+        // subEntry.name = account.name;
+        // subEntry.website = account.website;
+        // subEntry.avatar = account.imageUrl;
+        // backers.push(subEntry);
+      // });
+        entry.name = account.name;
+        entry.website = account.website;
+        entry.avatar = account.imageUrl;
+        entry.twitter = account.twitterHandle;
+        entry.slug = account.slug;
+        entry.type=account.type;
+        backers.push(entry);
     }
 
     if(!cached&&modifier)backers=modifier(backers);