diff --git a/src/lib/features/events/event-service.ts b/src/lib/features/events/event-service.ts index 45d4474c0c..282f4f97c9 100644 --- a/src/lib/features/events/event-service.ts +++ b/src/lib/features/events/event-service.ts @@ -104,16 +104,10 @@ export default class EventService { }; } - /** - * @deprecated use storeUserEvent instead - */ async storeEvent(event: IBaseEvent): Promise { return this.storeEvents([event]); } - /** - * @deprecated use storeUserEvents instead - */ async storeEvents(events: IBaseEvent[]): Promise { let enhancedEvents = events; for (const enhancer of [this.enhanceEventsWithTags.bind(this)]) { @@ -122,10 +116,18 @@ export default class EventService { return this.eventStore.batchStore(enhancedEvents); } + /** + * @deprecated this is tech debt, we should migrate to storeEvents and send the right + * userId and username parameters in IBaseEvent + */ async storeUserEvent(event: IUserEvent): Promise { return this.storeUserEvents([event]); } + /** + * @deprecated this is tech debt, we should migrate to storeEvents and send the right + * userId and username parameters in IBaseEvent + */ async storeUserEvents(events: IUserEvent[]): Promise { let enhancedEvents = events.map(({ byUser, ...event }) => { return { diff --git a/src/lib/types/events.ts b/src/lib/types/events.ts index 165e956363..6fa187d6ae 100644 --- a/src/lib/types/events.ts +++ b/src/lib/types/events.ts @@ -1304,11 +1304,11 @@ export class PotentiallyStaleOnEvent extends BaseEvent { } export class UserCreatedEvent extends BaseEvent { - readonly data: IUserWithRootRole; + readonly data: IUserEventData; constructor(eventData: { createdBy: string | IUser; - userCreated: IUserWithRootRole; + userCreated: IUserEventData; createdByUserId: number; }) { super(USER_CREATED, eventData.createdBy, eventData.createdByUserId); @@ -1317,13 +1317,13 @@ export class UserCreatedEvent extends BaseEvent { } export class UserUpdatedEvent extends BaseEvent { - readonly data: IUserWithRootRole; - readonly preData: IUserWithRootRole; + readonly data: IUserEventData; + readonly preData: IUserEventData; constructor(eventData: { createdBy: string | IUser; - preUser: IUserWithRootRole; - postUser: IUserWithRootRole; + preUser: IUserEventData; + postUser: IUserEventData; createdByUserId: number; }) { super(USER_UPDATED, eventData.createdBy, eventData.createdByUserId); @@ -1333,11 +1333,11 @@ export class UserUpdatedEvent extends BaseEvent { } export class UserDeletedEvent extends BaseEvent { - readonly preData: IUserWithRootRole; + readonly preData: IUserEventData; constructor(eventData: { createdBy: string | IUser; - deletedUser: IUserWithRootRole; + deletedUser: IUserEventData; createdByUserId: number; }) { super(USER_DELETED, eventData.createdBy, eventData.createdByUserId); @@ -1345,7 +1345,13 @@ export class UserDeletedEvent extends BaseEvent { } } -function mapUserToData(user: IUserWithRootRole): any { +interface IUserEventData + extends Pick< + IUserWithRootRole, + 'id' | 'name' | 'username' | 'email' | 'rootRole' + > {} + +function mapUserToData(user: IUserEventData): any { return { id: user.id, name: user.name,