/** * @public * @description Get house * @param {Object} [options] - Options of the query. * @param {Array} options.expand - Array of fields to expand. * @returns {Promise} Resolve with array of houses. * @example * const houses = await gladys.house.get(); */ async function get(options) { const optionsWithDefault = Object.assign({}, DEFAULT_OPTIONS, options); const queryParams = { include: [], order: [[optionsWithDefault.order_by, optionsWithDefault.order_dir]], }; if (optionsWithDefault.expand.includes('rooms')) { queryParams.include.push({ model: db.Room, as: 'rooms', }); } if (optionsWithDefault.search) { queryParams.where = Sequelize.where(Sequelize.fn('lower', Sequelize.col('t_house.name')), { [Op.like]: `%${optionsWithDefault.search}%`, }); } const houses = await db.House.findAll(queryParams); const housesPlain = houses.map((house) => house.get({ plain: true })); return housesPlain; }
queryParams.where = Sequelize.where(Sequelize.fn('lower', Sequelize.col('name')), { [Op.like]: `%${optionsWithDefault.search}%`, });
if (vm.name) and.push( sequelize.where(sequelize.fn('lower', sequelize.col('name')), { [sequelize.Op.like]: `%${vm.name.toLowerCase()}%` })