From fe06d0d6bd89494a73c52a28db20ea8fd7838a2f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 11 Jun 2025 21:05:17 +0200 Subject: [PATCH] Refactor API types and sync logic Rename and refactor the types passed over the API to be based on an entity that's either living or a tombstone. A living entity has a deleted property that's either undefined or false, while a tombstone has a deleted property set to true. All entities have a numeric id and an updatedAt timestamp. To sync entities, an array of replacements are passed around. Living entities are replaced with tombstones when they're deleted. And tombstones are replaced with living entities when restored. --- components/EventCard.vue | 29 ++-- components/EventsTable.vue | 86 +++++----- components/LocationsTable.vue | 68 ++++---- components/RolesTable.vue | 89 ++++++---- components/ScheduleTable.vue | 258 ++++++++++++++++------------- components/ShiftScheduleTable.vue | 246 +++++++++++++++------------- components/ShiftsTable.vue | 119 ++++++++------ components/Timetable.vue | 134 ++++++++++------ composables/event-source.ts | 4 +- composables/schedule.ts | 2 - package.json | 3 +- pages/edit.vue | 30 ++-- pages/schedule.vue | 34 ++-- pnpm-lock.yaml | 11 +- server/api/auth/account.patch.ts | 54 +++---- server/api/auth/account.post.ts | 4 +- server/api/auth/session.get.ts | 4 +- server/api/schedule.patch.ts | 103 ++++++------ server/api/schedule.ts | 6 +- server/api/subscribe.post.ts | 18 ++- server/database.ts | 11 +- server/generate-demo-schedule.ts | 259 +++++++++++++++++------------- server/streams.ts | 54 +++++-- server/utils/schedule.ts | 92 ++++++++--- server/utils/session.ts | 2 +- shared/types/account.d.ts | 25 --- shared/types/api.ts | 111 +++++++++++++ shared/types/common.ts | 25 +++ shared/types/schedule.d.ts | 65 -------- shared/utils/changes.ts | 21 --- shared/utils/functions.ts | 9 ++ shared/utils/update.ts | 14 ++ stores/account.ts | 47 ++++-- stores/schedules.ts | 27 +++- stores/session.ts | 4 +- utils/functions.ts | 8 + 36 files changed, 1242 insertions(+), 834 deletions(-) delete mode 100644 shared/types/account.d.ts create mode 100644 shared/types/api.ts create mode 100644 shared/types/common.ts delete mode 100644 shared/types/schedule.d.ts delete mode 100644 shared/utils/changes.ts create mode 100644 shared/utils/update.ts diff --git a/components/EventCard.vue b/components/EventCard.vue index cbf4c4d..b0345e7 100644 --- a/components/EventCard.vue +++ b/components/EventCard.vue @@ -1,5 +1,10 @@