Uploading minimal boilerplate
This commit is contained in:
1 parent
8516cac965
commit
5652cb9b6d
42 files changed
+8144
-1
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import EventStateEnum from '../types/enum/EventState';
|
||||
|
||||
const args = {
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
state: { type: EventStateEnum },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventId: _id, state }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOneAndUpdate({ _id, hostId }, { state }, { new: true }, (err, modifiedEvent) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(modifiedEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
changeEventState: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
Reference in new issue
Block a user