File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed
Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -875,6 +875,37 @@ class EventsFactory extends Factory {
875875 return collection . updateOne ( query , update ) ;
876876 }
877877
878+ /**
879+ * Remove a single event and all related data (repetitions, daily events)
880+ *
881+ * @param {string|ObjectId } eventId - id of the original event to remove
882+ * @return {Promise<void> }
883+ */
884+ async removeEvent ( eventId ) {
885+ const eventsCollection = this . getCollection ( this . TYPES . EVENTS ) ;
886+
887+ const event = await eventsCollection . findOne ( { _id : new ObjectId ( eventId ) } ) ;
888+
889+ if ( ! event ) {
890+ throw new Error ( `Event not found for eventId: ${ eventId } ` ) ;
891+ }
892+
893+ const { groupHash } = event ;
894+
895+ // Delete original event
896+ await eventsCollection . deleteOne ( { _id : new ObjectId ( eventId ) } ) ;
897+
898+ // Delete all repetitions with same groupHash
899+ if ( await this . isCollectionExists ( this . TYPES . REPETITIONS ) ) {
900+ await this . getCollection ( this . TYPES . REPETITIONS ) . deleteMany ( { groupHash } ) ;
901+ }
902+
903+ // Delete all daily event records with same groupHash
904+ if ( await this . isCollectionExists ( this . TYPES . DAILY_EVENTS ) ) {
905+ await this . getCollection ( this . TYPES . DAILY_EVENTS ) . deleteMany ( { groupHash } ) ;
906+ }
907+ }
908+
878909 /**
879910 * Remove all project events
880911 *
Original file line number Diff line number Diff line change @@ -153,12 +153,29 @@ module.exports = {
153153 return ! ! result . acknowledged ;
154154 } ,
155155
156+ /**
157+ * Remove event and all related data (repetitions, daily events)
158+ *
159+ * @param {ResolverObj } _obj - resolver context
160+ * @param {string } projectId - project id
161+ * @param {string } eventId - event id to remove
162+ * @return {Promise<boolean> }
163+ */
164+ async removeEvent ( _obj , { projectId, eventId } , context ) {
165+ const factory = getEventsFactory ( context , projectId ) ;
166+
167+ await factory . removeEvent ( eventId ) ;
168+
169+ return true ;
170+ } ,
171+
156172 /**
157173 * Mutations namespace
158174 *
159175 * @return {Function() }
160176 */
161177 events : ( ) => ( { } ) ,
178+
162179 } ,
163180 EventsMutations : {
164181 /**
Original file line number Diff line number Diff line change @@ -504,6 +504,21 @@ extend type Mutation {
504504 mark: EventMark!
505505 ): Boolean!
506506
507+ """
508+ Remove event and all related data (repetitions, daily events)
509+ """
510+ removeEvent(
511+ """
512+ ID of project event is related to
513+ """
514+ projectId: ID!
515+
516+ """
517+ ID of the event to remove
518+ """
519+ eventId: ID!
520+ ): Boolean! @requireUserInWorkspace
521+
507522 """
508523 Namespace that contains only mutations related to the events
509524 """
You can’t perform that action at this time.
0 commit comments