Can not make MoreThanOrEqual work in TypeOrm

1k views Asked by At

I'm trying to make some filter, and meet the problem: MoreThanOrEqual is not working,

 this.freelanceRepo.find({
          join: {
              alias: "freelance",
              leftJoinAndSelect: {
                categories: "freelance.categories"
              }
          },
          order:{id:'ASC'},
          where:{price_hours:MoreThanOrEqual(30)}//is not working
      })

I tried also the query builders

this.freelanceRepo.createQueryBuilder("freelance")
        .leftJoinAndSelect("freelance.categories", "categories")
        .orderBy("freelance.id", "ASC")
        .where("freelance.price_hours = price_hours", {price_hours:MoreThanOrEqual(filterPrice)})
        .take(10)
        .skip(skippedItems)
        .getMany();

Here is my entity:

@Entity({name: "fl_freelance"})
export class Freelance {
    
    @PrimaryGeneratedColumn()
    id: number

    @Column({default: false})
    is_active: boolean

    @Column({nullable:true})
    price_hours: number
    
    @OneToOne(() => User, user => user.freelance)
    @JoinColumn({name: "users_id"})
    users: User

    @ManyToMany(() => Categories, categories => categories.freelance)
    categories: Categories[]
}

have no idea what was gone wrong, thanks for your answers

1

There are 1 answers

0
Vahan On

Thanks for answers, I have done it that way, and it works

return await this.freelanceRepo.createQueryBuilder("freelance")
        .leftJoinAndSelect("freelance.categories", "categories")
        .orderBy("freelance.id", "ASC")
        .where("freelance.price_hours >= :price_hours", {price_hours:10})
        .take(10)
        .skip(skippedItems)
        .getMany();