Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

cattr-app/server-application

87 stars
2 code files
View cattr-app/server-application on GitHub

app/Jobs/AssignAppsToTimeInterval.php

Open in GitHub
use App\Models\TimeInterval;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
 
class AssignAppsToTimeInterval implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable;
 
public int $uniqueFor = 60;
 
public function __construct(protected TimeInterval $interval)
{
}
 
public function uniqueId(): string
{
return $this->interval->id;
}
 
public function handle(): void
{
DB::table('tracked_applications')
->whereNull('time_interval_id')
->where('user_id', $this->interval->user_id)
->where('created_at', '>', $this->interval->start_at->setTimezone(config('app.timezone')))
->where('created_at', '<', $this->interval->end_at->setTimezone(config('app.timezone')))
->update(['time_interval_id' => $this->interval->id]);
}
}

app/Http/Controllers/Api/IntervalController.php

Open in GitHub
use App\Models\User;
use CatEvent;
use Filter;
use App\Jobs\AssignAppsToTimeInterval;
 
class IntervalController extends ItemController
{
// ...
 
public function create(CreateTimeIntervalRequest $request): JsonResponse
{
// ...
 
CatEvent::listen(
Filter::getAfterActionEventName(),
static function ($data) {
if (User::find($data['user_id'])->web_and_app_monitoring) {
AssignAppsToTimeInterval::dispatch($data);
}
}
);
 
return $this->_create($request);
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.