/** * @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}%`, });
type: optionsWithDefault.device_feature_type, }; queryParams.include[0].where = queryParams.include[0].where ? Sequelize.and(queryParams.include[0].where, condition) : condition; queryParams.where = { [Op.or]: [ Sequelize.where(Sequelize.fn('lower', Sequelize.col('t_device.name')), { [Op.like]: `%${optionsWithDefault.search}%`, }), Sequelize.where(Sequelize.fn('lower', Sequelize.col('t_device.external_id')), { [Op.like]: `%${optionsWithDefault.search}%`, }), service_id: service.id, }; queryParams.where = queryParams.where ? Sequelize.and(queryParams.where, condition) : condition; model: optionsWithDefault.model, }; queryParams.where = queryParams.where ? Sequelize.and(queryParams.where, condition) : condition;
where: { $and: [ sequelize.where( sequelize.fn('lower', sequelize.col('name')), sequelize.fn('lower', vm.name)
let and = []; if (vm.user_id) and.push(sequelize.where(sequelize.col('user_id'), parseInt(vm.user_id))); if (vm.profile_id) and.push( sequelize.where(sequelize.col('profile_id'), parseInt(vm.profile_id)) ); if (vm.name) and.push( sequelize.where(sequelize.fn('lower', sequelize.col('name')), { [sequelize.Op.like]: `%${vm.name.toLowerCase()}%` }) if (vm.is_active != null) and.push( sequelize.where( sequelize.col('is_active'), vm.is_active == 'true' ? 1 : 0