Notes/src/becca/entities/boption.ts

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-04-30 23:10:25 +02:00
"use strict";
2024-02-17 01:00:38 +02:00
import dateUtils = require('../../services/date_utils');
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
*/
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);
}
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;
}
init(): void {
// Do nothing.
}
2021-04-30 23:10:25 +02:00
beforeSaving() {
super.beforeSaving();
this.utcDateModified = dateUtils.utcNowDateTime();
}
getPojo() {
return {
name: this.name,
value: this.value,
isSynced: this.isSynced,
utcDateModified: this.utcDateModified
}
2021-04-30 23:10:25 +02:00
}
}
2024-02-17 01:00:38 +02:00
export = BOption;