Adding "includeOld" optional flag on current queries
Have to find a way to turn this into a "trait" in a way
This commit is contained in:
1 parent
f0b8ef0e54
commit
335024c646
2 files changed
+24
-5
No files matched your search
@@ -1,14 +1,25 @@
|
||||
import {
|
||||
GraphQLBoolean,
|
||||
GraphQLList
|
||||
} from 'graphql'
|
||||
import { epoch } from '../../utils/functions'
|
||||
import { CompetitionType } from '../types'
|
||||
import Competition from '../../models/competition'
|
||||
|
||||
const args = {
|
||||
includeOld: { type: GraphQLBoolean }
|
||||
}
|
||||
|
||||
const query = {
|
||||
competitions: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
args,
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find()
|
||||
return Competition.find(
|
||||
Object.assign(
|
||||
{},
|
||||
args.includeOld ? { finishDatetime: { $gt: epoch() } } : {}
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import {
|
||||
GraphQLBoolean,
|
||||
GraphQLList,
|
||||
GraphQLString,
|
||||
GraphQLNonNull
|
||||
} from 'graphql'
|
||||
import { epoch } from '../../utils/functions'
|
||||
import { CompetitionType } from '../types'
|
||||
import Competition from '../../models/competition'
|
||||
|
||||
const args = {
|
||||
host: { type: new GraphQLNonNull(GraphQLString) }
|
||||
host: { type: new GraphQLNonNull(GraphQLString) },
|
||||
includeOld: { type: GraphQLBoolean }
|
||||
}
|
||||
|
||||
const query = {
|
||||
@@ -15,9 +18,14 @@ const query = {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
args,
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find({
|
||||
host: args.host
|
||||
})
|
||||
return Competition.find(
|
||||
Object.assign(
|
||||
{
|
||||
host: args.host
|
||||
},
|
||||
args.includeOld ? { finishDatetime: { $gt: epoch() } } : {}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user