Setting queries

This commit is contained in:
Unknown committed 2019-03-16 12:27:08 +01:00
1 parent a17032c571
commit 8f690d5f5b
4 files changed
+37 -80

No files matched your search

-37
View File
@@ -1,37 +0,0 @@
import {
GraphQLInt,
GraphQLList,
} from 'graphql';
import { EventType } from '../types';
import { Event } from '../../models';
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
const args = {
minDate: { type: GraphQLInt },
maxDate: { type: GraphQLInt },
};
const resolve = (parent, { minDate, maxDate }) => Event.find(
Object.assign(
{ state: { $nin: [UNPUBLISHED, ARCHIVED] } },
minDate || maxDate
? {
startDatetime:
Object.assign(
minDate ? { $gte: minDate } : {},
maxDate ? { $lte: maxDate } : {},
),
}
: {},
),
);
const query = {
events: {
type: new GraphQLList(EventType),
args,
resolve,
},
};
export default query;
-39
View File
@@ -1,39 +0,0 @@
import {
GraphQLInt,
GraphQLList,
GraphQLString,
} from 'graphql';
import { EventType } from '../types';
import { Event } from '../../models';
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
const args = {
hostId: { type: GraphQLString },
minDate: { type: GraphQLInt },
maxDate: { type: GraphQLInt },
};
const resolve = (parent, { hostId, minDate, maxDate }, context) => Event.find(
Object.assign(
hostId ? { hostId, state: { $nin: [UNPUBLISHED, ARCHIVED] } } : { hostId: context.userId },
minDate || maxDate
? {
startDatetime:
Object.assign(
minDate ? { $gte: minDate } : {},
maxDate ? { $lte: maxDate } : {},
),
}
: {},
),
);
const query = {
eventsByHost: {
type: new GraphQLList(EventType),
args,
resolve,
},
};
export default query;
+35
View File
@@ -0,0 +1,35 @@
import {
GraphQLNonNull,
GraphQLID,
} from 'graphql';
import { DatabaseError } from '../../errors';
import { StrategyType } from '../types';
import { Strategy } from '../../models';
const args = {
fbId: { type: new GraphQLNonNull(GraphQLID) },
};
const resolve = (parent, { fbId }) => new Promise((res, rej) => {
Strategy.findOne({ fbId }).exec((err, event) => {
if (err) {
rej(err);
return;
}
if (!event) {
rej(new DatabaseError('None of the strategy are linked to that fbId'));
return;
}
res(event);
});
});
const query = {
strategyByFb: {
type: StrategyType,
args,
resolve,
},
};
export default query;
+2 -4
View File
@@ -2,14 +2,12 @@ import {
GraphQLObjectType,
} from 'graphql';
import EventsQuery from './Events';
import EventsByHostQuery from './EventsByHost';
import StrategyByFbQuery from './StrategyByFB';
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: Object.assign(
EventsQuery,
EventsByHostQuery,
StrategyByFbQuery,
),
});