@fabrix/spool-analytics
Version:
Spool: Analytics for Fabrix
70 lines (69 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@fabrix/fabrix/dist/common");
const spool_sequelize_1 = require("@fabrix/spool-sequelize");
class Analytic extends common_1.FabrixModel {
static get resolver() {
return spool_sequelize_1.SequelizeResolver;
}
static config(app, Sequelize) {
return {
options: {
underscored: true,
scopes: {
live: {
where: {
live_mode: true
}
}
}
}
};
}
static schema(app, Sequelize) {
const schema = {
start: {
type: Sequelize.DATE
},
end: {
type: Sequelize.DATE
},
name: {
type: Sequelize.STRING
},
group_label: {
type: Sequelize.STRING,
allowNull: true
},
labels: {
type: Sequelize.JSONB,
defaultValue: []
},
data: {
type: Sequelize.JSONB,
defaultValue: []
},
live_mode: {
type: Sequelize.BOOLEAN,
defaultValue: app.config.get('engine.live_mode')
}
};
return schema;
}
static associate(models) {
}
}
exports.Analytic = Analytic;
Analytic.prototype.toJSON = function () {
const resp = this instanceof this.app.models['Analytic'].instance ? this.get({ plain: true }) : this;
if (this.trend) {
resp.trend = this.trend;
}
if (this.trend_range) {
resp.trend_range = this.trend_range;
}
if (this.trend_date_range) {
resp.trend_date_range = this.trend_date_range;
}
return resp;
};