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:
Nikola Bjelo committed 2018-10-19 15:27:13 +02:00
1 parent f0b8ef0e54
commit 335024c646
2 files changed
+24 -5

No files matched your search

+12 -1
View File
@@ -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() } } : {}
)
)
}
}
}