Skip to content

Commit

Permalink
feat: add group-deleted event (#4816)
Browse files Browse the repository at this point in the history
Adds a missing `group-deleted` event.
  • Loading branch information
nunogois committed Sep 22, 2023
1 parent b4742df commit b6b0f83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/lib/services/group-service.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -170,8 +170,18 @@ export class GroupService {
return [];
}

async deleteGroup(id: number): Promise<void> {
return this.groupStore.delete(id);
async deleteGroup(id: number, userName?: string): Promise<void> {
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(
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/events.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -213,6 +214,7 @@ export const IEventTypes = [
SEGMENT_DELETED,
GROUP_CREATED,
GROUP_UPDATED,
GROUP_DELETED,
SETTING_CREATED,
SETTING_UPDATED,
SETTING_DELETED,
Expand Down

0 comments on commit b6b0f83

Please sign in to comment.