2018-05-22 12:15:54 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
2018-05-22 12:22:43 +08:00
|
|
|
const dateUtils = require('../services/date_utils');
|
2018-05-22 12:15:54 +08:00
|
|
|
|
2018-08-23 05:37:06 +08:00
|
|
|
/**
|
|
|
|
* Option represents name-value pair, either directly configurable by the user or some system property.
|
|
|
|
*
|
2019-11-09 16:36:08 +08:00
|
|
|
* @property {string} name
|
|
|
|
* @property {string} value
|
|
|
|
* @property {boolean} isSynced
|
|
|
|
* @property {string} utcDateModified
|
|
|
|
* @property {string} utcDateCreated
|
2018-08-23 05:37:06 +08:00
|
|
|
*
|
|
|
|
* @extends Entity
|
|
|
|
*/
|
2018-05-22 12:15:54 +08:00
|
|
|
class Option extends Entity {
|
2018-08-17 05:00:04 +08:00
|
|
|
static get entityName() { return "options"; }
|
2018-06-14 07:10:28 +08:00
|
|
|
static get primaryKeyName() { return "name"; }
|
|
|
|
static get hashedProperties() { return ["name", "value"]; }
|
2018-05-22 12:22:43 +08:00
|
|
|
|
2018-08-07 17:38:00 +08:00
|
|
|
constructor(row) {
|
|
|
|
super(row);
|
|
|
|
|
|
|
|
this.isSynced = !!this.isSynced;
|
|
|
|
}
|
|
|
|
|
2018-05-22 12:22:43 +08:00
|
|
|
beforeSaving() {
|
2019-03-25 04:06:38 +08:00
|
|
|
if (!this.utcDateCreated) {
|
|
|
|
this.utcDateCreated = dateUtils.utcNowDateTime();
|
|
|
|
}
|
|
|
|
|
2018-08-06 14:59:26 +08:00
|
|
|
super.beforeSaving();
|
2018-08-13 02:04:48 +08:00
|
|
|
|
|
|
|
if (this.isChanged) {
|
2019-03-14 05:43:59 +08:00
|
|
|
this.utcDateModified = dateUtils.utcNowDateTime();
|
2018-08-13 02:04:48 +08:00
|
|
|
}
|
2018-05-22 12:22:43 +08:00
|
|
|
}
|
2018-05-22 12:15:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Option;
|