Skip to content

ifError not working for entity methods #499

Open
@Traigor

Description

@Traigor

Describe the bug
ifError() is not working for methods of entities.
When we call an entity (or root entity) method with ifError(), the .value member is not being added in the fail check.
See example below:

To Reproduce
For the following Entity in bl:

Entity ModuleEntity {
    static create(props: ModuleProps): (OK(ModuleEntity), Errors()) 
    {}
    public rename(name: ModuleNameVO): (OK(void), Errors()) {
        this.name = name;
    }
}

when we call the rename method in a command handler, for example:

const name = ModuleNameVO.create({name: command.name}).ifError();
module.rename(name).ifError();

In typescript will be generated the following code in the command handler:

const result_713354 = module.value.rename(name.value);
    if (result_713354.isFail()) {
      return fail(result_713354);
    }

Expected behavior
The generated code should have the .value in fail function:

const result_713354 = module.value.rename(name.value);
    if (result_713354.isFail()) {
      return fail(result_713354.value);
    }

Temporary Solution
Instead of (OK(void), Errors()) we can declare void as return type of the method:

public rename(name: ModuleNameVO): void  {
        this.name = name;
    }

In this case in the command handler in bl we will write:

const name = ModuleNameVO.create({name: command.name}).ifError();
module.rename(name);

and the typescript code generated will be:

module.value.rename(name.value);

without the fail check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions