From 2c84ceb1ab4dbde6895e29c849d7880268f7a2fb Mon Sep 17 00:00:00 2001 From: Sendou Date: Fri, 14 Jun 2019 16:15:10 +0300 Subject: [PATCH] fixed user page bug displaying twitter at incorrect times --- index.js | 25 +++++++++++++++++++ react-ui/src/components/Misc/Admin.js | 0 .../src/components/SoloLadder/UserPage.js | 6 ++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 react-ui/src/components/Misc/Admin.js diff --git a/index.js b/index.js index 4105676a7..904154cc0 100644 --- a/index.js +++ b/index.js @@ -229,6 +229,10 @@ const typeDefs = gql` username: String! password: String! ): Token + updateTwitter( + unique_id: String! + twitter: String! + ): Boolean addBuild( weapon: String! title: String @@ -239,6 +243,9 @@ const typeDefs = gql` deleteBuild( id: ID! ): Boolean + updateBuild( + build: Build! + ): Boolean } ` @@ -598,6 +605,23 @@ const resolvers = { } }, Mutation: { + editTwitter: async (root, args, ctx) => { + if (!ctx.user.id !== PROCESS.ENV.ADMIN_ID) throw new AuthenticationError('not admin') + + const player = await Player.findOne({ unique_id: args.unique_id }) + + player.twitter = args.twitter.toLowerCase() + + try { + await player.save() + } catch (error) { + throw new UserInputError(error.message, { + invalidArgs: args, + }) + } + + return true + }, addBuild: async (root, args, ctx) => { if (!ctx.user) throw new AuthenticationError('User not logged in.') if (args.title) if (args.title.length > 100) throw new UserInputError('Title too long.', { @@ -646,6 +670,7 @@ const resolvers = { }, Player: { discord_id: async (root) => { + if (!root.twitter) return null const user = await User .findOne({ twitter_name: root.twitter }) .catch(e => { diff --git a/react-ui/src/components/Misc/Admin.js b/react-ui/src/components/Misc/Admin.js new file mode 100644 index 000000000..e69de29bb diff --git a/react-ui/src/components/SoloLadder/UserPage.js b/react-ui/src/components/SoloLadder/UserPage.js index 081d74fbd..2cc9837ee 100644 --- a/react-ui/src/components/SoloLadder/UserPage.js +++ b/react-ui/src/components/SoloLadder/UserPage.js @@ -15,10 +15,14 @@ const UserPage = ({ userIdOrName }) => { return
} - if (error || userLeanQuery.loading) { + if (error) { return
{error.message}
} + if (userLeanQuery.error) { + return
{userLeanQuery.error.message}
+ } + const userData = data.searchForUser if (!userData) return