2021-04-30 23:10:25 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-02-17 01:00:38 +02:00
|
|
|
import dateUtils = require('../../services/date_utils');
|
2024-02-17 11:16:00 +02:00
|
|
|
import AbstractBeccaEntity = require('./abstract_becca_entity');
|
2024-02-17 01:00:38 +02:00
|
|
|
import { OptionRow } from './rows';
|
2021-04-30 23:10:25 +02:00
|
|
|
|
|
|
|
/**
|
2023-06-30 11:18:34 +02:00
|
|
|
* Option represents a name-value pair, either directly configurable by the user or some system property.
|
2021-04-30 23:10:25 +02:00
|
|
|
*/
|
2024-02-17 11:13:53 +02:00
|
|
|
class BOption extends AbstractBeccaEntity<BOption> {
|
2021-04-30 23:10:25 +02:00
|
|
|
static get entityName() { return "options"; }
|
|
|
|
static get primaryKeyName() { return "name"; }
|
|
|
|
static get hashedProperties() { return ["name", "value"]; }
|
|
|
|
|
2024-02-17 01:00:38 +02:00
|
|
|
name!: string;
|
|
|
|
value!: string;
|
|
|
|
isSynced!: boolean;
|
|
|
|
|
2024-02-17 20:45:31 +02:00
|
|
|
constructor(row?: OptionRow) {
|
2021-04-30 23:10:25 +02:00
|
|
|
super();
|
|
|
|
|
2024-02-17 20:45:31 +02:00
|
|
|
if (row) {
|
|
|
|
this.updateFromRow(row);
|
|
|
|
}
|
2023-02-22 22:10:41 +01:00
|
|
|
this.becca.options[this.name] = this;
|
|
|
|
}
|
|
|
|
|
2024-02-17 01:00:38 +02:00
|
|
|
updateFromRow(row: OptionRow) {
|
2021-04-30 23:10:25 +02:00
|
|
|
this.name = row.name;
|
|
|
|
this.value = row.value;
|
|
|
|
this.isSynced = !!row.isSynced;
|
|
|
|
this.utcDateModified = row.utcDateModified;
|
|
|
|
}
|
|
|
|
|
2024-03-30 11:09:45 +02:00
|
|
|
init(): void {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
|
2021-04-30 23:10:25 +02:00
|
|
|
beforeSaving() {
|
|
|
|
super.beforeSaving();
|
|
|
|
|
|
|
|
this.utcDateModified = dateUtils.utcNowDateTime();
|
2021-05-08 22:13:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getPojo() {
|
|
|
|
return {
|
|
|
|
name: this.name,
|
|
|
|
value: this.value,
|
|
|
|
isSynced: this.isSynced,
|
2021-11-18 22:39:12 +01:00
|
|
|
utcDateModified: this.utcDateModified
|
2021-05-08 22:13:08 +02:00
|
|
|
}
|
2021-04-30 23:10:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 01:00:38 +02:00
|
|
|
export = BOption;
|