Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ifError not working for entity methods #499

Open
Traigor opened this issue Jun 29, 2023 · 0 comments
Open

ifError not working for entity methods #499

Traigor opened this issue Jun 29, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Traigor
Copy link
Contributor

Traigor commented Jun 29, 2023

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.

@Traigor Traigor added the bug Something isn't working label Jun 29, 2023
@Traigor Traigor changed the title .value isn't added to result of entity method ifError not working for entity methods Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant