Browse Source

Added values to account details endpoint

Will Browning 3 năm trước cách đây
mục cha
commit
01016337ec

+ 4 - 0
app/Http/Resources/UserResource.php

@@ -25,9 +25,13 @@ class UserResource extends JsonResource
             'email_subject' => $this->email_subject,
             'email_subject' => $this->email_subject,
             'banner_location' => $this->banner_location,
             'banner_location' => $this->banner_location,
             'bandwidth' => $this->bandwidth,
             'bandwidth' => $this->bandwidth,
+            'username_count' => $this->username_count,
             'default_recipient_id' => $this->default_recipient_id,
             'default_recipient_id' => $this->default_recipient_id,
             'default_alias_domain' => $this->default_alias_domain,
             'default_alias_domain' => $this->default_alias_domain,
             'default_alias_format' => $this->default_alias_format,
             'default_alias_format' => $this->default_alias_format,
+            'recipient_count' => $this->recipients()->count(),
+            'active_domain_count' => $this->domains()->where('active', true)->count(),
+            'active_shared_domain_alias_count' => $this->activeSharedDomainAliases()->count(),
             'total_emails_forwarded' => (int) $totals->forwarded,
             'total_emails_forwarded' => (int) $totals->forwarded,
             'total_emails_blocked' => (int) $totals->blocked,
             'total_emails_blocked' => (int) $totals->blocked,
             'total_emails_replied' => (int) $totals->replied,
             'total_emails_replied' => (int) $totals->replied,

+ 16 - 0
app/Models/User.php

@@ -259,6 +259,22 @@ class User extends Authenticatable implements MustVerifyEmail
         return $this->hasManyThrough(AliasRecipient::class, Alias::class);
         return $this->hasManyThrough(AliasRecipient::class, Alias::class);
     }
     }
 
 
+    /**
+     * Get all of the user's aliases using a shared domain.
+     */
+    public function sharedDomainAliases()
+    {
+        return $this->aliases()->whereIn('domain', config('anonaddy.all_domains'));
+    }
+
+    /**
+     * Get all of the user's active aliases using a shared domain.
+     */
+    public function activeSharedDomainAliases()
+    {
+        return $this->sharedDomainAliases()->where('active', true);
+    }
+
     /**
     /**
      * Get all of the user's aliases that are using the default recipient
      * Get all of the user's aliases that are using the default recipient
      */
      */