apps/recallassess/recallassess-api/src/api/client/participant/listeners/participant-activity.listener.ts
Event Listener for Participant Activity Tracking Subscribes to participant activity events and updates last_login timestamps
This decouples activity tracking from business logic:
Properties |
|
Methods |
constructor(activityService: CLParticipantActivityService)
|
||||||
|
Parameters :
|
| Async handleParticipantActivity | ||||||
handleParticipantActivity(event: ParticipantActivityEvent)
|
||||||
Decorators :
@OnEvent(PARTICIPANT_EVENTS.ACTIVITY)
|
||||||
|
Handle participant activity event Updates last_login timestamp whenever participant performs an action
Parameters :
Returns :
any
|
| Private Readonly logger |
Type : unknown
|
Default value : new Logger(ParticipantActivityListener.name)
|
import { Injectable, Logger } from "@nestjs/common";
import { OnEvent } from "@nestjs/event-emitter";
import { PARTICIPANT_EVENTS, ParticipantActivityEvent } from "../events/participant.events";
import { CLParticipantActivityService, ParticipantActivityType } from "../participant-activity.service";
/**
* Event Listener for Participant Activity Tracking
* Subscribes to participant activity events and updates last_login timestamps
*
* This decouples activity tracking from business logic:
* - Services emit activity events (don't know about tracking)
* - This listener reacts to events (updates timestamps)
* - Clean separation of concerns
*/
@Injectable()
export class ParticipantActivityListener {
private readonly logger = new Logger(ParticipantActivityListener.name);
constructor(private readonly activityService: CLParticipantActivityService) {}
/**
* Handle participant activity event
* Updates last_login timestamp whenever participant performs an action
*/
@OnEvent(PARTICIPANT_EVENTS.ACTIVITY)
async handleParticipantActivity(event: ParticipantActivityEvent) {
try {
this.logger.debug(`Activity event: Participant ${event.participantId} - ${event.activityType}`);
await this.activityService.updateLastActivity(event.participantId, event.activityType, event.metadata);
this.logger.debug(`Successfully updated last activity for participant ${event.participantId}`);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
const errorStack = error instanceof Error ? error.stack : undefined;
this.logger.error(`Failed to update last activity: ${errorMessage}`, errorStack);
// Don't throw - activity tracking should not fail the main operation
}
}
}