team invitation notification with broadcasting

This commit is contained in:
Čarodej
2022-03-10 16:23:13 +01:00
parent 64e80d387b
commit 9ae2d54a5e
50 changed files with 331 additions and 201 deletions

View File

@@ -1,10 +1,7 @@
<?php
namespace App\Users\Resources;
use ByteUnits\Metric;
use Carbon\CarbonPeriod;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -23,18 +20,18 @@ class UserStorageResource extends JsonResource
$totalCapacity = match (get_settings('subscription_type')) {
'metered' => $this->usedCapacity / 1000000000,
'fixed' => $this->limitations->max_storage_amount,
default => $this->limitations->max_storage_amount,
'fixed' => $this->limitations->max_storage_amount,
default => $this->limitations->max_storage_amount,
};
return [
'data' => [
'id' => (string)$this->id,
'id' => (string) $this->id,
'type' => 'storage',
'attributes' => [
'used' => Metric::bytes($this->usedCapacity)->format(),
'capacity' => format_gigabytes($totalCapacity),
'percentage' => (float)get_storage_percentage($this->usedCapacity, $totalCapacity),
'percentage' => (float) get_storage_percentage($this->usedCapacity, $totalCapacity),
],
'meta' => [
'traffic' => [
@@ -47,23 +44,23 @@ class UserStorageResource extends JsonResource
],
'images' => [
'used' => Metric::bytes($images)->format(),
'percentage' => (float)get_storage_percentage($images, $totalCapacity),
'percentage' => (float) get_storage_percentage($images, $totalCapacity),
],
'audios' => [
'used' => Metric::bytes($audios)->format(),
'percentage' => (float)get_storage_percentage($audios, $totalCapacity),
'percentage' => (float) get_storage_percentage($audios, $totalCapacity),
],
'videos' => [
'used' => Metric::bytes($videos)->format(),
'percentage' => (float)get_storage_percentage($videos, $totalCapacity),
'percentage' => (float) get_storage_percentage($videos, $totalCapacity),
],
'documents' => [
'used' => Metric::bytes($documents)->format(),
'percentage' => (float)get_storage_percentage($documents, $totalCapacity),
'percentage' => (float) get_storage_percentage($documents, $totalCapacity),
],
'others' => [
'used' => Metric::bytes($others)->format(),
'percentage' => (float)get_storage_percentage($others, $totalCapacity),
'percentage' => (float) get_storage_percentage($others, $totalCapacity),
],
],
],
@@ -134,12 +131,12 @@ class UserStorageResource extends JsonResource
->where('created_at', '>', $period)
->orderBy('created_at')
->get(['upload', 'download', 'created_at'])
->each(fn($record) => $record->created_at = format_date($record->created_at, 'd. M. Y'))
->each(fn ($record) => $record->created_at = format_date($record->created_at, 'd. M. Y'))
->keyBy('created_at');
$mappedTrafficRecords = mapTrafficRecords($trafficRecords);
$upload = $mappedTrafficRecords->map(fn($record) => [
$upload = $mappedTrafficRecords->map(fn ($record) => [
'created_at' => $record->created_at,
'amount' => Metric::bytes($record->upload)->format(),
'percentage' => intval($uploadMax) !== 0
@@ -147,7 +144,7 @@ class UserStorageResource extends JsonResource
: 0,
]);
$download = $mappedTrafficRecords->map(fn($record) => [
$download = $mappedTrafficRecords->map(fn ($record) => [
'created_at' => $record->created_at,
'amount' => Metric::bytes($record->download)->format(),
'percentage' => intval($downloadMax) !== 0