From 85241993c738e3c6379a2e7183bbe2841fccc128 Mon Sep 17 00:00:00 2001 From: quangtuanitmo18 Date: Mon, 2 Mar 2026 02:45:07 +0300 Subject: [PATCH 1/2] feat: add api remove event --- src/models/eventsFactory.js | 33 +++++++++++++++++++++++++++++++++ src/resolvers/event.js | 16 ++++++++++++++++ src/typeDefs/event.ts | 15 +++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/src/models/eventsFactory.js b/src/models/eventsFactory.js index bf3efb13..c9c5fb13 100644 --- a/src/models/eventsFactory.js +++ b/src/models/eventsFactory.js @@ -875,6 +875,39 @@ class EventsFactory extends Factory { return collection.updateOne(query, update); } + /** + * Remove a single event and all related data (repetitions, daily events) + * + * @param {string|ObjectId} eventId - id of the original event to remove + * @return {Promise} + */ + async removeEvent(eventId) { + const eventsCollection = this.getCollection(this.TYPES.EVENTS); + + const event = await eventsCollection.findOne({ _id: new ObjectId(eventId) }); + + if (!event) { + throw new Error(`Event not found for eventId: ${eventId}`); + } + + const { groupHash } = event; + + // Delete original event + const result = await eventsCollection.deleteOne({ _id: new ObjectId(eventId) }); + + // Delete all repetitions with same groupHash + if (await this.isCollectionExists(this.TYPES.REPETITIONS)) { + await this.getCollection(this.TYPES.REPETITIONS).deleteMany({ groupHash }); + } + + // Delete all daily event records with same groupHash + if (await this.isCollectionExists(this.TYPES.DAILY_EVENTS)) { + await this.getCollection(this.TYPES.DAILY_EVENTS).deleteMany({ groupHash }); + } + + return result; + } + /** * Remove all project events * diff --git a/src/resolvers/event.js b/src/resolvers/event.js index c3c44971..06f1f33b 100644 --- a/src/resolvers/event.js +++ b/src/resolvers/event.js @@ -153,6 +153,22 @@ module.exports = { return !!result.acknowledged; }, + /** + * Remove event and all related data (repetitions, daily events) + * + * @param {ResolverObj} _obj - resolver context + * @param {string} projectId - project id + * @param {string} eventId - event id to remove + * @return {Promise} + */ + async removeEvent(_obj, { projectId, eventId }, context) { + const factory = getEventsFactory(context, projectId); + + const result = await factory.removeEvent(eventId); + + return !!result.acknowledged; + }, + /** * Mutations namespace * diff --git a/src/typeDefs/event.ts b/src/typeDefs/event.ts index c200de96..a182061b 100644 --- a/src/typeDefs/event.ts +++ b/src/typeDefs/event.ts @@ -504,6 +504,21 @@ extend type Mutation { mark: EventMark! ): Boolean! + """ + Remove event and all related data (repetitions, daily events) + """ + removeEvent( + """ + ID of project event is related to + """ + projectId: ID! + + """ + ID of the event to remove + """ + eventId: ID! + ): Boolean! @requireUserInWorkspace + """ Namespace that contains only mutations related to the events """ From bd7cbe520ed0750253e41050bf5c929e6c78d31f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:14:59 +0000 Subject: [PATCH 2/2] Bump version up to 1.4.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ab0a13c..8d8b9bca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.4.7", + "version": "1.4.8", "main": "index.ts", "license": "BUSL-1.1", "scripts": {