Bladeren bron

Added values to account details endpoint

Will Browning 3 jaren geleden
bovenliggende
commit
01016337ec
2 gewijzigde bestanden met toevoegingen van 20 en 0 verwijderingen
  1. 4 0
      app/Http/Resources/UserResource.php
  2. 16 0
      app/Models/User.php

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

@@ -25,9 +25,13 @@ class UserResource extends JsonResource
             'email_subject' => $this->email_subject,
             'banner_location' => $this->banner_location,
             'bandwidth' => $this->bandwidth,
+            'username_count' => $this->username_count,
             'default_recipient_id' => $this->default_recipient_id,
             'default_alias_domain' => $this->default_alias_domain,
             '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_blocked' => (int) $totals->blocked,
             '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);
     }
 
+    /**
+     * 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
      */