import {EventsHandler, IEventHandler} from "@nestjs/cqrs";
import {UserPropertyChangedEvent} from "../../../guests/event-handlers/user-property-changed.event";
import {SharedService} from "../../../shared/shared.service";
import {SocketEvents} from "../../../shared/events.consts";

@EventsHandler(UserPropertyChangedEvent)
export class UserPropertyChangedEventHandler implements IEventHandler<UserPropertyChangedEvent> {
  constructor(private sharedService: SharedService) {
  }
  handle(event: UserPropertyChangedEvent): any {
    this.sharedService.sendSocketNotificationToAllClients(
      SocketEvents.USER_PROPERTY_CHANGED,
      { user: event.user, property: event.property, value: event.propertyValue }
    );
  }

}