fixed user page bug displaying twitter at incorrect times

This commit is contained in:
Sendou
2019-06-14 16:15:10 +03:00
parent 7481d1c8ee
commit 2c84ceb1ab
3 changed files with 30 additions and 1 deletions

View File

@@ -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 => {

0
react-ui/src/components/Misc/Admin.js vendored Normal file
View File

View File

@@ -15,10 +15,14 @@ const UserPage = ({ userIdOrName }) => {
return <div style={{"paddingTop": "25px", "paddingBottom": "20000px"}} ><Loader active inline='centered' /></div>
}
if (error || userLeanQuery.loading) {
if (error) {
return <div style={{"color": "red"}}>{error.message}</div>
}
if (userLeanQuery.error) {
return <div style={{"color": "red"}}>{userLeanQuery.error.message}</div>
}
const userData = data.searchForUser
if (!userData) return <Redirect to='/404' />