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

EntityFromBody does not work params undefined #3

Open
Christian24 opened this issue May 22, 2017 · 2 comments
Open

EntityFromBody does not work params undefined #3

Christian24 opened this issue May 22, 2017 · 2 comments

Comments

@Christian24
Copy link

Hello,

I have the following controller:

@JsonController("/countries")
export class CountriesController {
private countryRepository: Repository<Country>;
constructor() {
    this.countryRepository = getEntityManager().getRepository(Country);
}
@Get()
getAll() {
return this.countryRepository.find();
}
@Get("/:id")
getOne(@Param("id") id: number) {
return this.countryRepository.createQueryBuilder("country").leftJoinAndSelect("country.specialities","speciality")
    .leftJoinAndSelect("country.thingsToNote","thingToNote").where("country.id = :id", {id}).getOne();
}

@Post("/:id")
@Authorized()
    create(@EntityFromBody() country: Country, @Res() res: Response) {
if(country) {
   return this.countryRepository.persist(country);
} else {
    res.send("No information provided")
}
}
}

It does not compile with the following error:

node_modules\typeorm-routing-controllers-extensions\decorators\EntityFromBody.js:15
        MetadataArgsStorage_1.defaultMetadataArgsStorage.params.push({
                                                        ^

TypeError: Cannot read property 'params' of undefined
    at C:\Users\Chris\Documents\acropolis\node_modules\typeorm-routing-controllers-extensions\decorators\EntityFromBody.js:15:57
    at C:\Users\Chris\Documents\acropolis\routes\countries.js:12:37
    at DecorateProperty (C:\Users\Chris\Documents\acropolis\node_modules\reflect-metadata\Reflect.js:530:29)
    at Object.decorate (C:\Users\Chris\Documents\acropolis\node_modules\reflect-metadata\Reflect.js:100:20)
    at __decorate (C:\Users\Chris\Documents\acropolis\routes\countries.js:4:92)
    at Object.<anonymous> (C:\Users\Chris\Documents\acropolis\routes\countries.js:52:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

````
Could it be that there is a bug there and that the array params needs to be instantiated first?

Thanks a lot,
Christian
@pleerock
Copy link
Member

pleerock commented Jun 7, 2017

Can you reproduce your issue with the latest version of routing-controllers and this package?

@Christian24
Copy link
Author

Yes, I can:

TypeError: Cannot read property 'params' of undefined
    at C:\Users\Chris\Documents\acropolis\node_modules\typeorm-routing-controllers-extensions\decorators\EntityFromBody.js:15:57
    at C:\Users\Chris\Documents\acropolis\routes\cities.js:12:37
    at DecorateProperty (C:\Users\Chris\Documents\acropolis\node_modules\reflect-metadata\Reflect.js:530:29)
    at Object.decorate (C:\Users\Chris\Documents\acropolis\node_modules\reflect-metadata\Reflect.js:100:20)
    at __decorate (C:\Users\Chris\Documents\acropolis\routes\cities.js:4:92)
    at Object.<anonymous> (C:\Users\Chris\Documents\acropolis\routes\cities.js:106:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

Just did a quick test somewhere in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants