fix: push scheduler handles all-day events and adds debug logging
- Query both timed (startDateTime) and all-day (startDate) events - All-day events treated as starting at 07:00 UTC (~09:00 CET) - Log number of events found per user for debugging - Skip already-passed events to avoid unnecessary checks v1.37.2
This commit is contained in:
parent
c28fa71e4d
commit
a32e5601d0
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "my-weekly-todo-list",
|
||||
"version": "1.37.1",
|
||||
"version": "1.37.2",
|
||||
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -66,23 +66,42 @@ async function run() {
|
||||
const windowEnd = new Date(now);
|
||||
windowEnd.setDate(windowEnd.getDate() + 7);
|
||||
|
||||
// Find events with reminders: both timed and all-day
|
||||
const events = await prisma.cachedCalendarEvent.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
startDateTime: { gte: now, lte: windowEnd },
|
||||
reminders: { not: null },
|
||||
OR: [
|
||||
{ startDateTime: { gte: now, lte: windowEnd } },
|
||||
{ startDate: { not: null } },
|
||||
],
|
||||
},
|
||||
select: {
|
||||
externalId: true,
|
||||
title: true,
|
||||
startDateTime: true,
|
||||
startDate: true,
|
||||
reminders: true,
|
||||
calendarTitle: true,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`[Push Scheduler] Found ${events.length} events with reminders for user ${user.id}`);
|
||||
|
||||
for (const event of events) {
|
||||
if (!event.startDateTime || !event.reminders) continue;
|
||||
// Determine the event start time
|
||||
let eventStart: Date | null = event.startDateTime;
|
||||
if (!eventStart && event.startDate) {
|
||||
// All-day events: treat as starting at 09:00 local time (user timezone)
|
||||
// Parse the date string and set to 09:00 UTC as approximation
|
||||
// (for CET/CEST this means ~10:00/11:00 local, close enough for day-before reminders)
|
||||
eventStart = new Date(event.startDate + 'T07:00:00.000Z');
|
||||
}
|
||||
if (!eventStart || !event.reminders) continue;
|
||||
|
||||
// Skip events that already passed
|
||||
const maxReminderMinutes = 10080; // 1 week
|
||||
if (eventStart.getTime() + maxReminderMinutes * 60 * 1000 < now.getTime()) continue;
|
||||
|
||||
let reminders: Reminder[] = [];
|
||||
try {
|
||||
@ -96,7 +115,7 @@ async function run() {
|
||||
if (reminder.minutes < 0) continue;
|
||||
|
||||
// Calculate when notification should fire
|
||||
const notifyAt = new Date(event.startDateTime.getTime() - reminder.minutes * 60 * 1000);
|
||||
const notifyAt = new Date(eventStart.getTime() - reminder.minutes * 60 * 1000);
|
||||
|
||||
// Check if we're within the 1-minute window
|
||||
const diffMs = Math.abs(now.getTime() - notifyAt.getTime());
|
||||
@ -116,7 +135,7 @@ async function run() {
|
||||
if (alreadySent) continue;
|
||||
|
||||
// Build notification payload
|
||||
const timeStr = event.startDateTime.toLocaleTimeString('en-US', {
|
||||
const timeStr = eventStart.toLocaleTimeString('en-US', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user