/** * @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), }, }); }
created_at: { [Op.gte]: fromDate, [Op.lte]: toDate, }, },
where.start = { [Op.gte]: new Date(fromDate), [Op.lte]: new Date(toDate), };
const buildMinMaxWhereClause = (min, max) => { const clauses = [] if (min) clauses.push({ [Sequelize.Op.gte]: min }) if (max) clauses.push({ [Sequelize.Op.lte]: max }) return { [Sequelize.Op.and]: clauses } }