-
Notifications
You must be signed in to change notification settings - Fork 1
3. First feature
When a hero slays a dragon, he gets a new item in his inventory, but you may have noticed that, for now, he cannot do anything with it. Let's change that ! Here's your ticket: As a Hero, I can equip an item and it improves my attack. Try to do it on your own but you can check the commits if you need help.
git checkout -b feature-hero-equip-item
In heroes/core/domain/hero.entity.ts, add an equippedItem property to the Hero entity, and modify the getHeroAttackValue function to take it in account (keep it simple for now). Commit your first changes: First commit.
Now you want to modify this new property, let's use the DDD Hexagonal Generator to create a new command EquipItem.
3 files should have been created, let's get rid of the equip-item.port.ts for now.
- You will likely need the id of the Hero equipping the item and the id of the item, add them in the payload of the command in
equip-item.command.ts. - In
equip-item.command-handler.ts, change the port being injected in the constructor to@Inject(Hero) private readonly heroPorts: UpdatePort<Hero>. This means that you will use a port of the entity Hero to update it. There are similar ports to Get, Create, or Delete an entity. - In the execute method of the handler, use the payload to make the correct update.
- In
heroes/core/application/hero.applications, don't forget to add your new application. - Commit your changes: Second commit