Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
How can the result of multiplying two columns be used when filtering? Postgres, Sequilize

Help solve the problem. The table contains the fields price and quantity. One of the filtering parameters in the request comes the cost. How to correctly and beautifully write filtering by the cost parameter using Sequilize:

    const DESC = query.desc ? 'DESC' : 'ASC';

    const where = {
      ...(query.square_from && {
        square_feet: {
          [Op.gte]: query.square_from,
        },
      }),
      ...(query.square_to && {
        square_feet: {
          [Op.lte]: query.square_to,
        },
      }),
      //??????????????????????????????????????????????????????????
      ...(query.total_price_from &&
        Sequelize.where(Sequelize.literal('token_price*lot_size'), {
          [Op.gte]: query.total_price_from,
        })),
      //?????????????????????????????????????????????????????????
    };

    return await this.propertySchema.findAndCountAll({
      where,
      attributes: { exclude: ['createdAt', 'updatedAt'] },
      order: [[query.orderby, DESC]],
      limit: PROPERTIES_BY_PAGE,
      offset: +(query.page - 1) * PROPERTIES_BY_PAGE,
      distinct: true,
      include: [
        {
          model: Files,
          attributes: { exclude: ['createdAt', 'updatedAt'] },
          through: {
            attributes: ['is_main'],
          },
        },
      ],
    });
  }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!