You can use class constructor to initialize class member variables when you create the instance of the class. Thank you for informative tutorials by the way :). ex) export class ResponseAddEvent { constructor(private userId: number, private optionId: number) {} } ---- @Post() async handleQuestionResponse() { // insert data into the response table console.log('controller'); this.eventEmitter.emit( events.RESPONSE_SUBMITTED, new ResponseAddEvent(1, 3), // userId, optionId ); return { message: 'Response taken' }; }
Great video! Trying to reproduce the events in one of my projects, I encountered a problem... The event is only emitted once, but the OnEvent listener is firing twice. Any idea why??
@@amitavroydev thank you for the response! After a bit of digging around, I found out that it is due to circular imports of services... No circular dependencies error though. I would love to hop on a short call and show you the code :) No fix found yet
@@amitavroydev I would love to, but sadly it is a project we are currently working on in our company. I'll try to creat a new nest project and reproduce it so that you can also play around with it. Sounds good?
You can use class constructor to initialize class member variables when you create the instance of the class. Thank you for informative tutorials by the way :).
ex)
export class ResponseAddEvent {
constructor(private userId: number, private optionId: number) {}
}
----
@Post()
async handleQuestionResponse() {
// insert data into the response table
console.log('controller');
this.eventEmitter.emit(
events.RESPONSE_SUBMITTED,
new ResponseAddEvent(1, 3), // userId, optionId
);
return { message: 'Response taken' };
}
Glad you liked it
how can this events trigger an server side event?? using rxjs to push an event to te client?
This is entirely server side my friend
Which VSCODE theme are you using? Can anyone please tell me??
Github theme Dark
Great video! Trying to reproduce the events in one of my projects, I encountered a problem... The event is only emitted once, but the OnEvent listener is firing twice. Any idea why??
That’s strange. Ideally it should not happen but it’s difficult to say what exactly is the problem without looking at the code
@@amitavroydev thank you for the response! After a bit of digging around, I found out that it is due to circular imports of services... No circular dependencies error though. I would love to hop on a short call and show you the code :) No fix found yet
Can you share the code using github?
@@amitavroydev I would love to, but sadly it is a project we are currently working on in our company. I'll try to creat a new nest project and reproduce it so that you can also play around with it. Sounds good?
Sounds good
how to do e2e test on this?
I haven't tried e2e with Nest. So, won't be able to help you in that.
What is the theme in vscode that you are using? I want to try that!
Hmm.. I keep changing.. however, if I am not wrong this is Github Dark or it will me Material theme dark.
Need to add a constructor in ResponseAddEvent, then you can initialize the class in one line.
Can you share an example. Sorry, I don’t think I completely understand what you are saying
export class ResponseAddEvent {
constructor(userId,optionId){}
userId
optionId
}
Then you can do
new ResponseAddEvent(userId, optionId)
*The problem that you’re trying to solve the last 2 mins in your tutorial.
which theme are you using for vs code?
This is Material UI
@@amitavroydev Thanks and for icons?
This makes sense, however you need to clarify that you're blending CQRS with microservices.
He isn’t using Microservices
Yeah, I am not using Microservices.