diff --git a/src/graphql/resolvers/Mutation/adminDeleteMeeting.js b/src/graphql/resolvers/Mutation/adminDeleteMeeting.js new file mode 100644 index 00000000..fa9d3ff6 --- /dev/null +++ b/src/graphql/resolvers/Mutation/adminDeleteMeeting.js @@ -0,0 +1,43 @@ +import { ApolloError } from 'apollo-server-errors'; +import { deleteCalendarEvent } from '../../../googleApis/calendar'; + +export default async ( + root, + { meetingId }, + { + adminRoleRequired, + models: { meetings, googleCalendarEvents, googleCalendars } + } +) => { + const meeting = await meetings.idLoader.load(meetingId); + + if (!meeting) { + throw new ApolloError( + "There's no meeting with that id", + 'MEETING_NOT_FOUND' + ); + } + + adminRoleRequired('charters') + + /*const meetingCalEvent = await googleCalendarEvents.meetingIdLoader.load( + meeting.id + );*/ + const meetingCalEvent = await googleCalendarEvents.findOne({ + where: { + meetingId: meetingId, + recurringMeeting: false + } + }); + + const gCal = await googleCalendars.orgIdLoader.load(meeting.organizationId); + + if (meetingCalEvent) { + await deleteCalendarEvent(gCal.gCalId, meetingCalEvent.gCalEventId); + await meetingCalEvent.destroy(); + } + + await meeting.destroy(); + + return true; +}; diff --git a/src/graphql/resolvers/Mutation/index.js b/src/graphql/resolvers/Mutation/index.js index 5f868ace..72dfe59e 100644 --- a/src/graphql/resolvers/Mutation/index.js +++ b/src/graphql/resolvers/Mutation/index.js @@ -1,4 +1,5 @@ import addRoomToMeeting from './addRoomToMeeting'; +import adminDeleteMeeting from './adminDeleteMeeting'; import alterCharter from './alterCharter'; import alterClubFairResponse from './alterClubFairResponse'; import alterEmailSettings from './alterEmailSettings'; @@ -51,6 +52,7 @@ import createUser from './createUser'; export default { linkOAuthPlatform, login, + adminDeleteMeeting, alterCharter, alterClubFairResponse, alterEmailSettings, diff --git a/src/graphql/schema/Mutation.js b/src/graphql/schema/Mutation.js index 31570bc6..16179f76 100644 --- a/src/graphql/schema/Mutation.js +++ b/src/graphql/schema/Mutation.js @@ -177,7 +177,8 @@ export default gql` createPromotedClub(orgId: Int!, blurb: String!): PromotedClub deletePromotedClub(promotedClubId: Int!): Boolean - # --- settings --- + # --- admin --- + adminDeleteMeeting(meetingId: Int!): Boolean alterSettings(membershipRequirement: Int!): Settings # --- users ---