diff --git a/clients/javascript/tests/calendarEvent.spec.ts b/clients/javascript/tests/calendarEvent.spec.ts index 6d25b212..c997e430 100644 --- a/clients/javascript/tests/calendarEvent.spec.ts +++ b/clients/javascript/tests/calendarEvent.spec.ts @@ -281,7 +281,7 @@ describe('CalendarEvent API', () => { expect(resEventTokyo.event).toBeDefined() expect(resEventTokyo.event.calendarId).toBe(calendarTokyoId) expect(resEventTokyo.event.recurringUntil).toEqual( - dayjs('2024-12-12T15:29:59.000Z').toDate() // 30 minutes after until + dayjs('2024-12-12T14:59:59.000Z').toDate() ) expect(resEventTokyo.event.recurrence).toEqual( expect.objectContaining({ @@ -528,11 +528,13 @@ describe('CalendarEvent API', () => { const eventId = res.event.id // Test updating recurrence + const until = new Date(3000).toISOString() const res2 = await adminClient.events.update(eventId, { recurrence: { freq: 'weekly', interval: 2, count: 10, + until: until, }, }) @@ -543,6 +545,8 @@ describe('CalendarEvent API', () => { count: 10, }) ) + expect(dayjs(res2.event.recurrence?.until)).toEqual(dayjs(until)) + expect(res2.event.recurringUntil).toEqual(dayjs(until).toDate()) // Test setting recurrence to NULL const res3 = await adminClient.events.update(eventId, { @@ -550,6 +554,7 @@ describe('CalendarEvent API', () => { }) expect(res3.event.recurrence).toBeNull() + expect(res3.event.recurringUntil).toBeNull() }) it('should handle recurring event fields', async () => { diff --git a/crates/api/src/event/update_event.rs b/crates/api/src/event/update_event.rs index 3f84277a..cbc2e6c0 100644 --- a/crates/api/src/event/update_event.rs +++ b/crates/api/src/event/update_event.rs @@ -321,6 +321,7 @@ impl UseCase for UpdateEventUseCase { } else { // Set to NULL e.recurrence = None; + e.recurring_until = None; true } // Otherwise, we we don't have a new recurrence, but we have an existing one @@ -336,6 +337,7 @@ impl UseCase for UpdateEventUseCase { })? } else { e.recurrence = None; + e.recurring_until = None; true } } else { diff --git a/crates/domain/src/event.rs b/crates/domain/src/event.rs index 6814422d..a19bd0a4 100644 --- a/crates/domain/src/event.rs +++ b/crates/domain/src/event.rs @@ -169,10 +169,7 @@ impl CalendarEvent { return Ok(false); } - // Add duration to until if it is set - self.recurring_until = recurrence - .until - .map(|until| until + TimeDelta::milliseconds(self.duration)); + self.recurring_until = recurrence.until; // Set the recurrence self.recurrence = Some(recurrence); diff --git a/crates/infra/.sqlx/query-12e4cb314134f5167c2b5bfc3b42c90494a1dd89813b0dd9b0e858ffdcec8083.json b/crates/infra/.sqlx/query-250856069a28f5dee536a708622b2fe03661a19ae98b1cc43fc0a320b02add79.json similarity index 96% rename from crates/infra/.sqlx/query-12e4cb314134f5167c2b5bfc3b42c90494a1dd89813b0dd9b0e858ffdcec8083.json rename to crates/infra/.sqlx/query-250856069a28f5dee536a708622b2fe03661a19ae98b1cc43fc0a320b02add79.json index 016f8c8c..4deffe6c 100644 --- a/crates/infra/.sqlx/query-12e4cb314134f5167c2b5bfc3b42c90494a1dd89813b0dd9b0e858ffdcec8083.json +++ b/crates/infra/.sqlx/query-250856069a28f5dee536a708622b2fe03661a19ae98b1cc43fc0a320b02add79.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT event_uid, calendar_uid, user_uid, account_uid, external_parent_id, external_id, title, description, event_type, location, all_day, status, start_time, duration, busy, end_time, created, updated, recurrence_jsonb, recurring_until, exdates, recurring_event_uid, original_start_time, reminders_jsonb, service_uid, metadata FROM calendar_events AS e\n WHERE e.calendar_uid = any($1::uuid[])\n AND (\n (e.start_time <= $2 AND e.end_time >= $3)\n OR \n (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until > $3))\n )\n ", + "query": "\n SELECT event_uid, calendar_uid, user_uid, account_uid, external_parent_id, external_id, title, description, event_type, location, all_day, status, start_time, duration, busy, end_time, created, updated, recurrence_jsonb, recurring_until, exdates, recurring_event_uid, original_start_time, reminders_jsonb, service_uid, metadata FROM calendar_events AS e\n WHERE e.calendar_uid = any($1::uuid[])\n AND (\n (e.start_time <= $2 AND e.end_time >= $3)\n OR \n (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until >= $3))\n )\n ", "describe": { "columns": [ { @@ -170,5 +170,5 @@ false ] }, - "hash": "12e4cb314134f5167c2b5bfc3b42c90494a1dd89813b0dd9b0e858ffdcec8083" + "hash": "250856069a28f5dee536a708622b2fe03661a19ae98b1cc43fc0a320b02add79" } diff --git a/crates/infra/.sqlx/query-ac33a78c2d15f32199209b7e480ebce5aee0e4c783f021078e2160def3d7e746.json b/crates/infra/.sqlx/query-6308a907be08687565bfff2d1264832f711a039b89681e4b874adf008ac27a84.json similarity index 95% rename from crates/infra/.sqlx/query-ac33a78c2d15f32199209b7e480ebce5aee0e4c783f021078e2160def3d7e746.json rename to crates/infra/.sqlx/query-6308a907be08687565bfff2d1264832f711a039b89681e4b874adf008ac27a84.json index 3f4fa504..2068b701 100644 --- a/crates/infra/.sqlx/query-ac33a78c2d15f32199209b7e480ebce5aee0e4c783f021078e2160def3d7e746.json +++ b/crates/infra/.sqlx/query-6308a907be08687565bfff2d1264832f711a039b89681e4b874adf008ac27a84.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT event_uid, calendar_uid, user_uid, account_uid, external_parent_id, external_id, title, description, event_type, location, all_day, status, start_time, duration, busy, end_time, created, updated, recurrence_jsonb, recurring_until, exdates, recurring_event_uid, original_start_time, reminders_jsonb, service_uid, metadata FROM calendar_events AS e\n WHERE e.calendar_uid = $1\n AND (\n (e.start_time <= $2 AND e.end_time >= $3)\n OR\n (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until > $3))\n )\n ", + "query": "\n SELECT event_uid, calendar_uid, user_uid, account_uid, external_parent_id, external_id, title, description, event_type, location, all_day, status, start_time, duration, busy, end_time, created, updated, recurrence_jsonb, recurring_until, exdates, recurring_event_uid, original_start_time, reminders_jsonb, service_uid, metadata FROM calendar_events AS e\n WHERE e.calendar_uid = $1\n AND (\n (e.start_time <= $2 AND e.end_time >= $3)\n OR\n (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until >= $3))\n )\n ", "describe": { "columns": [ { @@ -170,5 +170,5 @@ false ] }, - "hash": "ac33a78c2d15f32199209b7e480ebce5aee0e4c783f021078e2160def3d7e746" + "hash": "6308a907be08687565bfff2d1264832f711a039b89681e4b874adf008ac27a84" } diff --git a/crates/infra/.sqlx/query-7bd47c5ffc7a88798087e8c535e68b38243670a2e691fdcc795552f6cfac9025.json b/crates/infra/.sqlx/query-fa89eaf94b8cdaf29179f5c2debac490cef3661dfd8f0fef08f15450b709e631.json similarity index 93% rename from crates/infra/.sqlx/query-7bd47c5ffc7a88798087e8c535e68b38243670a2e691fdcc795552f6cfac9025.json rename to crates/infra/.sqlx/query-fa89eaf94b8cdaf29179f5c2debac490cef3661dfd8f0fef08f15450b709e631.json index 8816c9e3..26e09e30 100644 --- a/crates/infra/.sqlx/query-7bd47c5ffc7a88798087e8c535e68b38243670a2e691fdcc795552f6cfac9025.json +++ b/crates/infra/.sqlx/query-fa89eaf94b8cdaf29179f5c2debac490cef3661dfd8f0fef08f15450b709e631.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT event_uid, calendar_uid, user_uid, account_uid, external_parent_id, external_id, title, description, event_type, location, all_day, status, start_time, duration, busy, end_time, created, updated, recurrence_jsonb, recurring_until, exdates, recurring_event_uid, original_start_time, reminders_jsonb, service_uid, metadata FROM calendar_events AS e\n WHERE e.calendar_uid = any($1::uuid[])\n AND (\n (e.start_time < $2 AND e.end_time > $3)\n OR\n (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until > $3))\n )\n AND busy = true\n AND status = any($4::text[])\n ", + "query": "\n SELECT event_uid, calendar_uid, user_uid, account_uid, external_parent_id, external_id, title, description, event_type, location, all_day, status, start_time, duration, busy, end_time, created, updated, recurrence_jsonb, recurring_until, exdates, recurring_event_uid, original_start_time, reminders_jsonb, service_uid, metadata FROM calendar_events AS e\n WHERE e.calendar_uid = any($1::uuid[])\n AND (\n (e.start_time < $2 AND e.end_time > $3)\n OR\n (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until >= $3))\n )\n AND busy = true\n AND status = any($4::text[])\n ", "describe": { "columns": [ { @@ -171,5 +171,5 @@ false ] }, - "hash": "7bd47c5ffc7a88798087e8c535e68b38243670a2e691fdcc795552f6cfac9025" + "hash": "fa89eaf94b8cdaf29179f5c2debac490cef3661dfd8f0fef08f15450b709e631" } diff --git a/crates/infra/src/repos/event/calendar_event/postgres.rs b/crates/infra/src/repos/event/calendar_event/postgres.rs index 4fe121e5..56bedf2c 100644 --- a/crates/infra/src/repos/event/calendar_event/postgres.rs +++ b/crates/infra/src/repos/event/calendar_event/postgres.rs @@ -617,7 +617,7 @@ impl IEventRepo for PostgresEventRepo { AND ( (e.start_time <= $2 AND e.end_time >= $3) OR - (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until > $3)) + (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until >= $3)) ) "#, calendar_id.as_ref(), @@ -680,7 +680,7 @@ impl IEventRepo for PostgresEventRepo { AND ( (e.start_time <= $2 AND e.end_time >= $3) OR - (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until > $3)) + (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until >= $3)) ) "#, &calendar_ids as &[Uuid], @@ -852,7 +852,7 @@ impl IEventRepo for PostgresEventRepo { AND ( (e.start_time < $2 AND e.end_time > $3) OR - (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until > $3)) + (e.start_time < $2 AND e.recurrence_jsonb IS NOT NULL AND (e.recurring_until IS NULL OR e.recurring_until >= $3)) ) AND busy = true AND status = any($4::text[])