Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda