usersForVoting endpoint

This commit is contained in:
Sendou
2019-12-31 18:53:01 +02:00
parent 5fea79e742
commit 7b68be59bb
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
import React from "react"
const Voting = () => {}
export default Voting

View File

@@ -13,6 +13,7 @@ const typeDef = gql`
plusInfo: PlusGeneralInfo
hasAccess(discord_id: String!, server: String!): Boolean!
suggestions: [Suggested!]!
usersForVoting: UsersForVoting!
}
extend type Mutation {
@@ -86,6 +87,11 @@ const typeDef = gql`
"Average of all scores of the voters for the month 0% to 100%"
score: Float!
}
type UsersForVoting {
users: [User!]!
suggested: [Suggested!]!
}
`
const resolvers = {
@@ -137,6 +143,36 @@ const resolvers = {
voting_ends: null,
}
},
usersForVoting: async (root, args, ctx) => {
if (!ctx.user) throw new UserInputError("Not logged in")
if (!ctx.user.plus || !ctx.user.plus.membership_status)
throw new UserInputError("Not plus server member")
const plus_server = ctx.user.plus.membership_status
const users = await User.find({
$or: [
{
"plus.membership_status": plus_server,
},
{ "plus.vouch_status": plus_server },
],
}).catch(e => {
throw (new Error(),
{
error: e,
})
})
const suggested = await Suggested.find({ plus_server }).catch(e => {
throw (new Error(),
{
error: e,
})
})
return { users, suggested }
},
suggestions: (root, args, ctx) => {
if (!ctx.user || !ctx.user.plus) return null
const searchCriteria =