From 171aa63df9865e44592b6348ce192654b2c6e5ed Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 18 Nov 2023 23:10:28 +0100 Subject: [PATCH] Improved update & add logic #410 --- bot/src/bot_data/model/scheduled_event.py | 2 +- .../mutations/scheduled_event_mutation.py | 17 +++-- .../queries/scheduled_event_history_query.py | 2 +- .../queries/scheduled_event_query.py | 2 +- .../app/models/data/scheduled_events.model.ts | 14 +++-- web/src/app/models/graphql/mutations.model.ts | 3 +- ...edit-scheduled-event-dialog.component.html | 4 +- .../edit-scheduled-event-dialog.component.ts | 63 +++++++++++++------ .../scheduled-events.component.html | 7 ++- .../scheduled-events.component.ts | 19 ++++-- 10 files changed, 91 insertions(+), 42 deletions(-) diff --git a/bot/src/bot_data/model/scheduled_event.py b/bot/src/bot_data/model/scheduled_event.py index 3f8fbee3..041cba28 100644 --- a/bot/src/bot_data/model/scheduled_event.py +++ b/bot/src/bot_data/model/scheduled_event.py @@ -168,7 +168,7 @@ class ScheduledEvent(TableABC): UPDATE `ScheduledEvents` SET `Interval` = '{self._interval.value}', `Name` = '{self._name}', - `Description` = '{self._start_time}', + `Description` = {"NULL" if self._description is None else f"'{self._description}'"}, `ChannelId` = {"NULL" if self._channel_id is None else f"'{self._channel_id}'"}, `StartTime` = '{self._start_time}', `EndTime` = {"NULL" if self._end_time is None else f"'{self._end_time}'"}, diff --git a/bot/src/bot_graphql/mutations/scheduled_event_mutation.py b/bot/src/bot_graphql/mutations/scheduled_event_mutation.py index 81353c62..43f1dd97 100644 --- a/bot/src/bot_graphql/mutations/scheduled_event_mutation.py +++ b/bot/src/bot_graphql/mutations/scheduled_event_mutation.py @@ -69,13 +69,22 @@ class ScheduledEventMutation(QueryABC): scheduled_event = self._scheduled_events.get_scheduled_event_by_id(input["id"]) self._can_user_mutate_data(scheduled_event.server, UserRoleEnum.moderator) - scheduled_event.short_name = input["shortName"] if "shortName" in input else scheduled_event.short_name - scheduled_event.interval = input["interval"] if "interval" in input else scheduled_event.interval + scheduled_event.interval = ( + ScheduledEventIntervalEnum(input["interval"]) if "interval" in input else scheduled_event.interval + ) scheduled_event.name = input["name"] if "name" in input else scheduled_event.name scheduled_event.description = input["description"] if "description" in input else scheduled_event.description scheduled_event.channel_id = input["channelId"] if "channelId" in input else scheduled_event.channel_id - scheduled_event.start_time = input["startTime"] if "startTime" in input else scheduled_event.start_time - scheduled_event.end_time = input["endTime"] if "endTime" in input else scheduled_event.end_time + scheduled_event.start_time = ( + datetime.strptime(input["startTime"], "%Y-%m-%dT%H:%M:%S.%fZ") + if "startTime" in input + else scheduled_event.start_time + ) + scheduled_event.end_time = ( + datetime.strptime(input["endTime"], "%Y-%m-%dT%H:%M:%S.%fZ") + if "endTime" in input + else scheduled_event.end_time + ) scheduled_event.entity_type = input["entityType"] if "entityType" in input else scheduled_event.entity_type scheduled_event.location = input["location"] if "location" in input else scheduled_event.location diff --git a/bot/src/bot_graphql/queries/scheduled_event_history_query.py b/bot/src/bot_graphql/queries/scheduled_event_history_query.py index 279bcda1..f8fe921a 100644 --- a/bot/src/bot_graphql/queries/scheduled_event_history_query.py +++ b/bot/src/bot_graphql/queries/scheduled_event_history_query.py @@ -13,7 +13,7 @@ class ScheduledEventHistoryQuery(DataQueryWithHistoryABC): self.set_field("id", lambda x, *_: x.id) self.set_field("id", lambda x, *_: x.id) - self.set_field("interval", lambda x, *_: x.interval) + self.set_field("interval", lambda x, *_: x.interval.value) self.set_field("name", lambda x, *_: x.name) self.set_field("description", lambda x, *_: x.description) self.set_field("channel_id", lambda x, *_: x.channel_id) diff --git a/bot/src/bot_graphql/queries/scheduled_event_query.py b/bot/src/bot_graphql/queries/scheduled_event_query.py index 47b09a1b..0cae786a 100644 --- a/bot/src/bot_graphql/queries/scheduled_event_query.py +++ b/bot/src/bot_graphql/queries/scheduled_event_query.py @@ -12,7 +12,7 @@ class ScheduledEventQuery(DataQueryWithHistoryABC): DataQueryWithHistoryABC.__init__(self, "ScheduledEvent", "ScheduledEventsHistory", ScheduledEventHistory, db) self.set_field("id", lambda x, *_: x.id) - self.set_field("interval", lambda x, *_: x.interval) + self.set_field("interval", lambda x, *_: x.interval.value) self.set_field("name", lambda x, *_: x.name) self.set_field("description", lambda x, *_: x.description) self.set_field("channelId", lambda x, *_: x.channel_id) diff --git a/web/src/app/models/data/scheduled_events.model.ts b/web/src/app/models/data/scheduled_events.model.ts index 972c10bb..e94db4b5 100644 --- a/web/src/app/models/data/scheduled_events.model.ts +++ b/web/src/app/models/data/scheduled_events.model.ts @@ -33,9 +33,11 @@ export interface ScheduledEventFilter { server?: ServerFilter; } -export enum ScheduledEventInterval { - daily = "daily", - weekly = "weekly", - monthly = "monthly", - yearly = "yearly" -} +// export enum ScheduledEventInterval { +// daily = "daily", +// weekly = "weekly", +// monthly = "monthly", +// yearly = "yearly" +// } + +export type ScheduledEventInterval = "daily" | "weekly" | "monthly" | "month" diff --git a/web/src/app/models/graphql/mutations.model.ts b/web/src/app/models/graphql/mutations.model.ts index 95843b64..bdac7b0c 100644 --- a/web/src/app/models/graphql/mutations.model.ts +++ b/web/src/app/models/graphql/mutations.model.ts @@ -204,9 +204,10 @@ export class Mutations { `; static updateScheduledEvent = ` - mutation updateScheduledEvent($interval: String,$name: String,$description: String,$channelId: String,$startTime: String, $endTime: String,$entityType: Int,$location: String, $serverId: ID) { + mutation updateScheduledEvent($id: ID, $interval: String,$name: String,$description: String,$channelId: String,$startTime: String, $endTime: String,$entityType: Int,$location: String, $serverId: ID) { scheduledEvent { updateScheduledEvent(input: { + id: $id, interval: $interval, name: $name, description: $description, diff --git a/web/src/app/modules/view/server/scheduled-events/components/edit-scheduled-event-dialog/edit-scheduled-event-dialog.component.html b/web/src/app/modules/view/server/scheduled-events/components/edit-scheduled-event-dialog/edit-scheduled-event-dialog.component.html index 62289884..fe5985ff 100644 --- a/web/src/app/modules/view/server/scheduled-events/components/edit-scheduled-event-dialog/edit-scheduled-event-dialog.component.html +++ b/web/src/app/modules/view/server/scheduled-events/components/edit-scheduled-event-dialog/edit-scheduled-event-dialog.component.html @@ -1,5 +1,5 @@
-
@@ -80,7 +80,7 @@
+ (click)="event = undefined">