-
app/Jobs/AssignAppsToTimeInterval.php
Open in GitHubuse 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 GitHubuse 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); } // ... }