From 97834240669cfed04d1cb7e9a5e1b6767e3033ee Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 28 Sep 2023 10:38:08 +0200 Subject: [PATCH] Fixed mutation #378 --- .../migration/db_history_scripts/short_rule_names.sql | 3 ++- kdb-bot/src/bot_data/model/short_role_name.py | 8 ++++---- kdb-bot/src/bot_graphql/graphql/shortRoleName.gql | 1 + .../bot_graphql/mutations/short_role_name_mutation.py | 9 +++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/kdb-bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql b/kdb-bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql index 06168a34..f4ff95c2 100644 --- a/kdb-bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql +++ b/kdb-bot/src/bot_data/migration/db_history_scripts/short_rule_names.sql @@ -30,7 +30,8 @@ CREATE TRIGGER `TR_ShortRoleNamesDelete` ON `ShortRoleNames` FOR EACH ROW BEGIN - INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `ServerId`, `Deleted`, `DateFrom`, + INSERT INTO `ShortRoleNamesHistory` (`Id`, `ShortName`, `DiscordRoleId`, `Position`, `ServerId`, `Deleted`, + `DateFrom`, `DateTo`) VALUES (OLD.Id, OLD.ShortName, OLD.DiscordRoleId, OLD.Position, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)); diff --git a/kdb-bot/src/bot_data/model/short_role_name.py b/kdb-bot/src/bot_data/model/short_role_name.py index 52b46444..4ddef4f1 100644 --- a/kdb-bot/src/bot_data/model/short_role_name.py +++ b/kdb-bot/src/bot_data/model/short_role_name.py @@ -107,12 +107,12 @@ class ShortRoleName(TableABC): return str( f""" INSERT INTO `ShortRoleNames` ( - `Name`, `DiscordRoleId`, `Position`, `ServerId` + `ShortName`, `DiscordRoleId`, `Position`, `ServerId` ) VALUES ( '{self._short_name}', - {self._discord_role_id} + {self._discord_role_id}, '{self._position}', - {self._server.id}, + {self._server.id} ); """ ) @@ -122,7 +122,7 @@ class ShortRoleName(TableABC): return str( f""" UPDATE `ShortRoleNames` - SET `Name` = '{self._short_name}', + SET `ShortName` = '{self._short_name}', `DiscordRoleId` = {self._discord_role_id}, `Position` = '{self._position}', `ServerId` = {self._server.id} diff --git a/kdb-bot/src/bot_graphql/graphql/shortRoleName.gql b/kdb-bot/src/bot_graphql/graphql/shortRoleName.gql index 263d7536..69df2920 100644 --- a/kdb-bot/src/bot_graphql/graphql/shortRoleName.gql +++ b/kdb-bot/src/bot_graphql/graphql/shortRoleName.gql @@ -46,4 +46,5 @@ input ShortRoleNameInput { roleId: String roleName: String position: String + serverId: ID } \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/mutations/short_role_name_mutation.py b/kdb-bot/src/bot_graphql/mutations/short_role_name_mutation.py index c8368112..3f3ca3af 100644 --- a/kdb-bot/src/bot_graphql/mutations/short_role_name_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/short_role_name_mutation.py @@ -36,10 +36,15 @@ class ShortRoleNameMutation(QueryABC): short_role_name = ShortRoleName( input["shortName"], - input["roleId"], + int(input["roleId"]), input["position"], server, ) + + result = self._short_role_names.find_short_role_name_by_role_id(short_role_name.role_id) + if result is not None: + raise ValueError("Short name for role already exists") + self._short_role_names.add_short_role_name(short_role_name) self._db.save_changes() @@ -47,7 +52,7 @@ class ShortRoleNameMutation(QueryABC): return ( srn.short_name == short_role_name.short_name and srn.role_id == short_role_name.role_id - and srn.position == short_role_name.position + and srn.position.value == short_role_name.position ) return (