From b6b0f83e3dcb956e83233362d7f201def75fb007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Fri, 22 Sep 2023 11:04:46 +0100 Subject: [PATCH] feat: add group-deleted event (#4816) Adds a missing `group-deleted` event. --- src/lib/services/group-service.ts | 16 +++++++++++++--- src/lib/types/events.ts | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/services/group-service.ts b/src/lib/services/group-service.ts index 589a5707ba..6e2644686e 100644 --- a/src/lib/services/group-service.ts +++ b/src/lib/services/group-service.ts @@ -11,7 +11,7 @@ import { IUnleashConfig, IUnleashStores } from '../types'; import { IGroupStore } from '../types/stores/group-store'; import { Logger } from '../logger'; import BadDataError from '../error/bad-data-error'; -import { GROUP_CREATED, GROUP_UPDATED } from '../types/events'; +import { GROUP_CREATED, GROUP_DELETED, GROUP_UPDATED } from '../types/events'; import { IEventStore } from '../types/stores/event-store'; import NameExistsError from '../error/name-exists-error'; import { IAccountStore } from '../types/stores/account-store'; @@ -170,8 +170,18 @@ export class GroupService { return []; } - async deleteGroup(id: number): Promise { - return this.groupStore.delete(id); + async deleteGroup(id: number, userName?: string): Promise { + const group = await this.groupStore.get(id); + + await this.groupStore.delete(id); + + if (userName) { + await this.eventStore.store({ + type: GROUP_DELETED, + createdBy: userName, + data: group, + }); + } } async validateGroup( diff --git a/src/lib/types/events.ts b/src/lib/types/events.ts index 68064d5c26..0ea5d04e20 100644 --- a/src/lib/types/events.ts +++ b/src/lib/types/events.ts @@ -90,6 +90,7 @@ export const SEGMENT_UPDATED = 'segment-updated' as const; export const SEGMENT_DELETED = 'segment-deleted' as const; export const GROUP_CREATED = 'group-created' as const; export const GROUP_UPDATED = 'group-updated' as const; +export const GROUP_DELETED = 'group-deleted' as const; export const SETTING_CREATED = 'setting-created' as const; export const SETTING_UPDATED = 'setting-updated' as const; export const SETTING_DELETED = 'setting-deleted' as const; @@ -213,6 +214,7 @@ export const IEventTypes = [ SEGMENT_DELETED, GROUP_CREATED, GROUP_UPDATED, + GROUP_DELETED, SETTING_CREATED, SETTING_UPDATED, SETTING_DELETED,