Skip to content

EntityFromBody does not work params undefined #3

@Christian24

Description

@Christian24

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions