mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 15:17:43 -05:00
upcomingEvents backend
This commit is contained in:
38
frontend-react/src/graphql/queries/upcomingEvents.ts
Normal file
38
frontend-react/src/graphql/queries/upcomingEvents.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { gql, DocumentNode } from "apollo-boost"
|
||||
import { User } from "../../types"
|
||||
|
||||
export interface UpcomingEventsData {
|
||||
upcomingEvents: {
|
||||
name: string
|
||||
date: string
|
||||
description: string
|
||||
message_url: string
|
||||
discord_invite_url: string
|
||||
picture_url?: string
|
||||
poster_discord_user: {
|
||||
username: string
|
||||
discriminator: string
|
||||
twitter_name?: string
|
||||
discord_id: string
|
||||
}
|
||||
}[]
|
||||
}
|
||||
|
||||
export const SEARCH_FOR_USER: DocumentNode = gql`
|
||||
{
|
||||
upcomingEvents {
|
||||
name
|
||||
date
|
||||
description
|
||||
message_url
|
||||
discord_invite_url
|
||||
picture_url
|
||||
poster_discord_user {
|
||||
username
|
||||
discriminator
|
||||
twitter_name
|
||||
discord_id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -3,6 +3,9 @@ const User = require("../mongoose-models/user")
|
||||
const CompetitiveFeedEvent = require("../mongoose-models/competitivefeedevent")
|
||||
|
||||
const typeDef = gql`
|
||||
extend type Query {
|
||||
upcomingEvents: [CompetitiveFeedEvent!]!
|
||||
}
|
||||
extend type Mutation {
|
||||
addCompetitiveFeedEvent(
|
||||
event: CompetitiveFeedEventInput!
|
||||
@@ -14,6 +17,7 @@ const typeDef = gql`
|
||||
date: String!
|
||||
description: String!
|
||||
poster_discord_id: String!
|
||||
poster_discord_user: User!
|
||||
message_discord_id: String!
|
||||
message_url: String!
|
||||
discord_invite_url: String!
|
||||
@@ -34,8 +38,15 @@ const typeDef = gql`
|
||||
}
|
||||
`
|
||||
const resolvers = {
|
||||
Query: {
|
||||
upcomingEvents: () => {
|
||||
return CompetitiveFeedEvent.find({ date: { $gte: new Date() } })
|
||||
.sort({ date: "asc" })
|
||||
.populate("poster_discord_user")
|
||||
},
|
||||
},
|
||||
Mutation: {
|
||||
addCompetitiveFeedEvent: async (root, args, ctx) => {
|
||||
addCompetitiveFeedEvent: async (_root, args) => {
|
||||
if (args.lohiToken !== process.env.LOHI_TOKEN) {
|
||||
throw new UserInputError("Invalid token provided")
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ competitiveFeedEventSchema.virtual("poster_discord_user", {
|
||||
ref: "User",
|
||||
localField: "poster_discord_id",
|
||||
foreignField: "discord_id",
|
||||
justOne: true,
|
||||
})
|
||||
|
||||
module.exports = mongoose.model(
|
||||
|
||||
Reference in New Issue
Block a user