Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda