mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
refactor: allow user events to take in only what they need (#6545)
This commit is contained in:
parent
ba53bd7bf9
commit
a2c4b8c320
@ -104,16 +104,10 @@ export default class EventService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use storeUserEvent instead
|
||||
*/
|
||||
async storeEvent(event: IBaseEvent): Promise<void> {
|
||||
return this.storeEvents([event]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use storeUserEvents instead
|
||||
*/
|
||||
async storeEvents(events: IBaseEvent[]): Promise<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
let enhancedEvents = events.map(({ byUser, ...event }) => {
|
||||
return {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user