connection .authenticate() .then(() => { console.info('INFO - Database connected.') }) .catch(err => { console.error('ERROR - Unable to connect to the database:', err) })
Promise.mapSeries(reversedSeed, (seed) => callLater().then(() => seed.down(db.sequelize.getQueryInterface())))
/** * @description Get messages of a user * @param {string} userId - The id of the user. * @param {Object} options - Options of the request. * @example * gladys.message.get('f6cc6e0c-1b48-4b59-8ac7-9a0ad2e0ed3c', options); */ async function get(userId, options) { const optionsWithDefault = Object.assign({}, DEFAULT_OPTIONS, options); const queryParams = { attributes: optionsWithDefault.fields, limit: optionsWithDefault.take, offset: optionsWithDefault.skip, order: [[optionsWithDefault.order_by, optionsWithDefault.order_dir]], where: { [Op.or]: [{ sender_id: userId }, { receiver_id: userId }], }, }; const messages = await db.Message.findAll(queryParams); const plainMessages = messages.map((message) => message.get({ plain: true })); return plainMessages; }
/** * @description Purge device states * @example * device.purgeStates(); */ async function purgeStates() { logger.debug('Purging device feature states...'); const deviceStateHistoryInDays = await this.variable.getValue(SYSTEM_VARIABLE_NAMES.DEVICE_STATE_HISTORY_IN_DAYS); const deviceStateHistoryInDaysInt = parseInt(deviceStateHistoryInDays, 10); if (Number.isNaN(deviceStateHistoryInDaysInt)) { logger.debug('Not purging device feature states.'); return; } const queryInterface = db.sequelize.getQueryInterface(); const now = new Date().getTime(); // all date before this timestamp will be removed const timstampLimit = now - deviceStateHistoryInDaysInt * 24 * 60 * 60 * 1000; await queryInterface.bulkDelete('t_device_feature_state', { created_at: { [Op.lte]: new Date(timstampLimit), }, }); }
db.sequelize.transaction(async (transaction) => { const service = await db.Service.findOne({ where: {
/** * @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; }
return db.sequelize.transaction(async (t) => { const locationWithUserId = Object.assign({}, location, { user_id: user.id,
last_value_changed: now, }); await db.sequelize.transaction(async (t) => {
Promise.mapSeries(seeds, (seed) => callLater().then(() => seed.up(db.sequelize.getQueryInterface())))
connection .authenticate() .then(() => { console.info('INFO - Database connected.') }) .catch(err => { console.error('ERROR - Unable to connect to the database:', err) })
db.sequelize.transaction(async (transaction) => { const service = await db.Service.findOne({ where: {