abolfazl81
abolfazl81

Reputation: 1

undefined in TypeORM and NestJS

 var name = await this.productRepo.findOne({where:{id}})['name']

Hi guys. I use typeorm and sqlite to get the property name from ProductEntity but I get undefined instead.

when I try to run var name = await this.productRepo.findOne({where:{id}}) i get something like that

ProductEntity {
    id: 1,
    name: 'فن لپتاپ',
    code: 'a57gr3f',
    quantity: 2,
    discription: 'ب',
    price: 3000000

} I am expected to get a فن لپتاپ instead of undefined I'll be thankfull if you help.

Upvotes: 0

Views: 376

Answers (1)

Micael Levi
Micael Levi

Reputation: 6665

await this.productRepo.findOne({where:{id}})['name']
//    \____________________________________/
//          this is an instance of Promise, not the resolved value
//          and Promise doesn't have the property 'name'

do this instead:

( await this.productRepo.findOne({where:{id}}) )['name']

Upvotes: 1

Related Questions