Adding a new mutation for updating event status
This commit is contained in:
1 parent
c22ff70868
commit
7347d472bd
2 files changed
+41
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 EventStatusEnum from '../types/enum/EventStatus';
|
||||
|
||||
const args = {
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
status: { type: EventStatusEnum },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventId: _id, status }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOneAndUpdate({ _id, hostId }, { status }, { new: true }, (err, modifiedEvent) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(modifiedEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
changeEventStatus: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -8,6 +8,7 @@ import RegisterToEventMutation from './RegisterToEvent';
|
||||
import EditParticipantMutation from './EditParticipant';
|
||||
import CreateFormulaMutation from './CreateFormula';
|
||||
import CreatePlotterMutation from './CreatePlotter';
|
||||
import ChangeEventStatusMutation from './ChangeEventStatus';
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
@@ -18,6 +19,7 @@ const Mutation = new GraphQLObjectType({
|
||||
EditParticipantMutation,
|
||||
CreateFormulaMutation,
|
||||
CreatePlotterMutation,
|
||||
ChangeEventStatusMutation,
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user