Feature/set up event system for portfolio changes (#3333)
* Set up event system for portfolio changes * Update changelogpull/3336/head
parent
a4efbc0131
commit
b692b7432c
@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { PortfolioChangedListener } from './portfolio-changed.listener';
|
||||
|
||||
@Module({
|
||||
providers: [PortfolioChangedListener]
|
||||
})
|
||||
export class EventsModule {}
|
@ -0,0 +1,15 @@
|
||||
export class PortfolioChangedEvent {
|
||||
private userId: string;
|
||||
|
||||
public constructor({ userId }: { userId: string }) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public static getName() {
|
||||
return 'portfolio.changed';
|
||||
}
|
||||
|
||||
public getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { PortfolioChangedEvent } from './portfolio-changed.event';
|
||||
|
||||
@Injectable()
|
||||
export class PortfolioChangedListener {
|
||||
@OnEvent(PortfolioChangedEvent.getName())
|
||||
handlePortfolioChangedEvent(event: PortfolioChangedEvent) {
|
||||
Logger.log(
|
||||
`Portfolio of user with id ${event.getUserId()} has changed`,
|
||||
'PortfolioChangedListener'
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue