Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetOrganizationPlanUsageQuery | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Organizations\Application\Queries; |
| 6 | |
| 7 | use App\Models\User; |
| 8 | use ImovelZapAi\Organizations\Application\Actions\EnsureOrganizationBootstrapAction; |
| 9 | use ImovelZapAi\Organizations\Infrastructure\Persistence\Eloquent\OrganizationSubscriptionModel; |
| 10 | use ImovelZapAi\Properties\Infrastructure\Persistence\Eloquent\PropertyModel; |
| 11 | use ImovelZapAi\Tenancy\Infrastructure\Persistence\Eloquent\TenantModel; |
| 12 | |
| 13 | final class GetOrganizationPlanUsageQuery |
| 14 | { |
| 15 | public function __construct( |
| 16 | private readonly EnsureOrganizationBootstrapAction $bootstrap, |
| 17 | ) {} |
| 18 | |
| 19 | /** |
| 20 | * @return array{ |
| 21 | * tenant: TenantModel, |
| 22 | * subscription: ?OrganizationSubscriptionModel, |
| 23 | * users_count: int, |
| 24 | * properties_count: int, |
| 25 | * max_users: int, |
| 26 | * max_properties: int, |
| 27 | * max_whatsapp_messages_month: int |
| 28 | * } |
| 29 | */ |
| 30 | public function execute(string $tenantId): array |
| 31 | { |
| 32 | $this->bootstrap->execute($tenantId); |
| 33 | |
| 34 | $tenant = TenantModel::query()->findOrFail($tenantId); |
| 35 | $subscription = OrganizationSubscriptionModel::query() |
| 36 | ->with('plan') |
| 37 | ->where('tenant_id', $tenantId) |
| 38 | ->first(); |
| 39 | |
| 40 | $plan = $subscription?->plan; |
| 41 | |
| 42 | return [ |
| 43 | 'tenant' => $tenant, |
| 44 | 'subscription' => $subscription, |
| 45 | 'users_count' => User::query()->where('tenant_id', $tenantId)->count(), |
| 46 | 'properties_count' => PropertyModel::query()->withoutGlobalScopes()->where('tenant_id', $tenantId)->count(), |
| 47 | 'max_users' => (int) ($plan?->max_users ?? 0), |
| 48 | 'max_properties' => (int) ($plan?->max_properties ?? 0), |
| 49 | 'max_whatsapp_messages_month' => (int) ($plan?->max_whatsapp_messages_month ?? 0), |
| 50 | ]; |
| 51 | } |
| 52 | } |