feat: add intervals

This commit is contained in:
2025-12-15 09:43:07 +03:30
parent a7b55b0b6d
commit ca946b2aae
+46 -20
View File
@@ -30,24 +30,52 @@ public function handle(): int
$this->info("Current time: {$now}");
$this->info("Current time string: {$currentTime}");
$reminders = Reminder::with(['user', 'packageName'])
->where(function ($query) use ($now, $currentTime) {
// For PostgreSQL: Cast datetime to time for comparison
$query->whereRaw('time::time <= ?', [$currentTime])
->where(function ($sub) use ($now) {
// Non-repeatable: send once
$sub->where('repeatable', false)
->whereNull('last_repeat')
// OR repeatable: not sent today
->orWhere('repeatable', true)
->where(function ($inner) use ($now) {
$inner->whereNull('last_repeat')
->orWhereDate('last_repeat', '<', $now->toDateString());
});
});
})
->get();
->where(function ($query) use ($now, $currentTime) {
// time reached today
$query->whereRaw('time::time <= ?', [$currentTime])
->where(function ($sub) use ($now) {
// non-repeatable (send once)
$sub->where('repeatable', false)
->whereNull('last_repeat')
// repeatable with interval
->orWhere(function ($repeat) use ($now) {
$repeat->where('repeatable', true)
->where(function ($interval) use ($now) {
$interval
->whereNull('last_repeat')
->orWhereRaw(
"last_repeat + (COALESCE(repeat_days, 1) || ' days')::interval <= ?",
[$now]
);
});
});
});
})
->get();
// $reminders = Reminder::with(['user', 'packageName'])
// ->where(function ($query) use ($now, $currentTime) {
// // For PostgreSQL: Cast datetime to time for comparison
// $query->whereRaw('time::time <= ?', [$currentTime])
// ->where(function ($sub) use ($now) {
// // Non-repeatable: send once
// $sub->where('repeatable', false)
// ->whereNull('last_repeat')
// // OR repeatable: not sent today
// ->orWhere('repeatable', true)
// ->where(function ($inner) use ($now) {
// $inner->whereNull('last_repeat')
// ->orWhereDate('last_repeat', '<', $now->toDateString());
// });
// });
// })
// ->get();
// Debug: Show what reminders were found
$this->info("Found {$reminders->count()} reminders");
@@ -91,9 +119,7 @@ public function handle(): int
);
}
$scheduledTime = Carbon::parse($reminder->time);
$scheduledTime->setDate($now->year, $now->month, $now->day);
$reminder->last_repeat = $scheduledTime;
$reminder->last_repeat = $now;
$reminder->save();
$this->info("Queued push notification for reminder {$reminder->id}.");
}