DigiChanges / node-experience

Hello! NExp (Node Experience) is a boilerplate for Node, which makes use of a Hexagonal architecture, in addition to all the power of TypeScript that combined allow a perfect cohesion thus achieving a clean and at the same time very powerful implementation.
https://nexp.docs.digichanges.com
MIT License
52 stars 36 forks source link

Refactor/nexp 206/ip/refactor event handler #240

Closed Rutito2010 closed 7 months ago

Rutito2010 commented 7 months ago

📜 Description

Bring back EventHandler from shared experience and refactored as an injectable dependency

🧪 Accept Criteria Tests

Once inyected the dependecy should work as a singleton dependecy Should execute eventhandler correctly

Manual test: -new event registration: -create a dummy event:

import { IEvent } from '../../Infrastructure/events';

class CreateItemEvent implements IEvent
{
    public name = CreateItemEvent.name;

    public handle = async() =>
    {
        `console.log('EventHandlerWorking')`
    };
}

export default CreateItemEvent;

set it at index.js

        const eventHandler = DependencyInjector.inject<IEventHandler>('IEventHandler');
        eventHandler.setEvent(new EmailEvent());
        eventHandler.setEvent(new SendMessageEvent());
        eventHandler.setEvent(new CreateItemEvent)  <---

inject the dependecy on SaveItemUseCase at the contructor:

this.eventHandler = DependencyInjector.inject<IEventHandler>('IEventHandler'); and execute the dummy event at any momento of the handle funcion

this.eventHandler.execute('CreateItemEvent', {})

a console.log result shows on the console indicating the event was succesfully emmited and executed

🔮 Last Notes

📋 Author Checklist

📋Reviewer Checklist