new route to mass update avas

This commit is contained in:
Sendou 2020-06-20 19:14:27 +03:00
parent 32fe982e25
commit 4a6b677962

View File

@ -17,6 +17,12 @@ const typeDef = gql`
"Returns all users"
users: [User!]!
}
input DiscordIdAvatar {
discordId: String!
avatar: String!
}
extend type Mutation {
updateUser(
country: String
@ -26,6 +32,7 @@ const typeDef = gql`
custom_url: String
bio: String
): Boolean
updateAvatars(lohiToken: String!, toUpdate: [DiscordIdAvatar!]!): Boolean
}
"The control sensitivity used in Splatoon 2"
@ -248,6 +255,22 @@ const resolvers = {
})
})
return true
},
updateAvatars: async (root, args) => {
if (args.lohiToken !== process.env.LOHI_TOKEN) {
throw new UserInputError("Invalid token")
}
await Promise.all(
args.toUpdate.map((user) =>
User.updateOne(
{ discord_id: user.discordId },
{ $set: { avatar: user.avatar } }
)
)
)
return true
},
},