typescriptnestjstypeorm

Typeorm and operator without using querybuilder


In NestJS / Typeform I want to make a query that sues to conditions as an AND condition.

I tried something like this

 async getByUniqueConstraints(user: User){
        const {email, phoneNumber} = user
        const foundUser = await this.userRepository.findOne({where: [email, phoneNumber], });

    }

The problem with this is that it uses an OR condition. Is there a way to use this with an AND operator instead without using a querybuilder or any more advanced concepts?


Solution

  • where with fields in curly braces uses AND operator. You can see it in docs here: https://github.com/typeorm/typeorm/blob/master/docs/docs/working-with-entity-manager/3-find-options.md