vulcainjs / vulcain-corejs

Microservice framework for nodejs
https://vulcainjs.github.io
Apache License 2.0
11 stars 3 forks source link

Cannot extends a Model #19

Closed workfel closed 7 years ago

workfel commented 7 years ago

Hi,

I tried to extends a Model for another Model, but it's not working ! I have 2 Model:


@Model()
export class DefaultParameter {

    @Property({ type: 'string', required: true })
    token: string;
}
@Model()
export class UserConnectedParameter extends DefaultParameter {
    @Property({ type: 'string', description: 'The url source.' })
    state: string;
}

The query Handler

@Query({ description: "Getting user connected", outputSchema: "UserInfoKeycloak", inputSchema: "UserConnectedParameter" }) // action = method name (minus Async)
    async meAsync(model: UserConnectedParameter): Promise<UserInfoKeycloak | { redirect: string }> {

        let currentUser: UserInfoKeycloak = await this.openidIssuerService.getCurrentUser(model.token);

        if (currentUser.error === 'invalid_token') {
            // call user service for
            let redirectUrl = this.openidIssuerService.getAuthorizationUrl(model.state);

            return { redirect: redirectUrl };
        }
        return currentUser;
    }

But when i'm debuging the model property i have only the state property.

It's the correct behavior ?

Thx

malain commented 7 years ago

Since typescript is just a transpiler and do not provide any information about a type on runtime, you must declare the extended class in the @Model attribute (of the extended class) with the 'extends' property.

rascaille commented 7 years ago

@Model(extends: 'DefaultParameter ')

aguerot commented 7 years ago

j ai mis à jour la doc sur http://www.vulcainjs.org/reference/domain/ avec un exemple de code