Harden credit flows and add RevenueCat webhook
This commit is contained in:
@@ -2,55 +2,39 @@
|
||||
|
||||
namespace App\Http\Resources\Tenant;
|
||||
|
||||
use App\Http\Resources\Tenant\EventTypeResource;
|
||||
use App\Http\Resources\Tenant\PhotoResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EventResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$tenantId = $request->attributes->get('tenant_id');
|
||||
|
||||
// Hide sensitive data for other tenants
|
||||
$showSensitive = $this->tenant_id === $tenantId;
|
||||
$settings = is_array($this->settings) ? $this->settings : [];
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'description' => $this->description,
|
||||
'event_date' => $this->event_date ? $this->event_date->toISOString() : null,
|
||||
'event_date' => $this->date ? $this->date->toISOString() : null,
|
||||
'location' => $this->location,
|
||||
'max_participants' => $this->max_participants,
|
||||
'current_participants' => $showSensitive ? $this->photos_count : null,
|
||||
'public_url' => $this->public_url,
|
||||
'custom_domain' => $showSensitive ? $this->custom_domain : null,
|
||||
'theme_color' => $this->theme_color,
|
||||
'status' => $showSensitive ? $this->status : 'published',
|
||||
'password_protected' => $this->password_protected,
|
||||
'features' => $this->features,
|
||||
'event_type' => new EventTypeResource($this->whenLoaded('eventType')),
|
||||
'photos' => PhotoResource::collection($this->whenLoaded('photos')),
|
||||
'tasks' => $showSensitive ? $this->whenLoaded('tasks') : [],
|
||||
'tenant' => $showSensitive ? [
|
||||
'id' => $this->tenant->id,
|
||||
'name' => $this->tenant->name,
|
||||
'event_credits_balance' => $this->tenant->event_credits_balance,
|
||||
] : null,
|
||||
'created_at' => $this->created_at->toISOString(),
|
||||
'updated_at' => $this->updated_at->toISOString(),
|
||||
'photo_count' => $this->photos_count,
|
||||
'like_count' => $this->photos->sum('likes_count'),
|
||||
'is_public' => $this->status === 'published' && !$this->password_protected,
|
||||
'public_share_url' => $showSensitive ? route('api.v1.events.show', ['slug' => $this->slug]) : null,
|
||||
'qr_code_url' => $showSensitive ? route('api.v1.events.qr', ['event' => $this->id]) : null,
|
||||
'current_participants' => $showSensitive ? ($this->photos_count ?? null) : null,
|
||||
'public_url' => $settings['public_url'] ?? null,
|
||||
'custom_domain' => $showSensitive ? ($settings['custom_domain'] ?? null) : null,
|
||||
'theme_color' => $settings['theme_color'] ?? null,
|
||||
'status' => $this->status ?? 'draft',
|
||||
'features' => $settings['features'] ?? [],
|
||||
'event_type_id' => $this->event_type_id,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
'photo_count' => $this->photos_count ?? 0,
|
||||
'like_count' => $this->whenLoaded('photos', fn () => $this->photos->sum('likes_count'), 0),
|
||||
'is_public' => $this->status === 'published',
|
||||
'public_share_url' => null,
|
||||
'qr_code_url' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user