This commit is contained in:
Timo Hocker 2020-05-05 11:48:46 +02:00
parent 400b68daf0
commit 433b2b5b27
3 changed files with 5 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import { Persistent } from './Persistent';
export abstract class ControlModel extends Persistent { export abstract class ControlModel extends Persistent {
public constructor (obj?: Record<string, string|number|boolean>) { public constructor (obj?: Record<string, string|number|boolean>) {
super (); super ();
this.define_properties ();
for (const prop of Object.keys (this.properties)) { for (const prop of Object.keys (this.properties)) {
if ([ if ([
'string', 'string',
@ -43,4 +44,5 @@ export abstract class ControlModel extends Persistent {
} }
public abstract verify(): void; public abstract verify(): void;
protected abstract define_properties(): void;
} }

View File

@ -15,6 +15,7 @@ export abstract class DatabaseModel extends Persistent {
public constructor (id?: number) { public constructor (id?: number) {
super (); super ();
this.properties.id = 'number'; this.properties.id = 'number';
this.define_properties ();
for (const prop of Object.keys (this.properties)) { for (const prop of Object.keys (this.properties)) {
if ([ if ([
'string', 'string',
@ -45,4 +46,5 @@ export abstract class DatabaseModel extends Persistent {
public abstract async read(): Promise<boolean>; public abstract async read(): Promise<boolean>;
public abstract async write(): Promise<boolean>; public abstract async write(): Promise<boolean>;
public abstract async delete(): Promise<boolean>; public abstract async delete(): Promise<boolean>;
protected abstract define_properties(): void;
} }

View File

@ -2,13 +2,7 @@ import { Assignable, Serializable } from './interfaces';
export abstract class Persistent implements Assignable, Serializable { export abstract class Persistent implements Assignable, Serializable {
private _data: Record<string, unknown> = {}; private _data: Record<string, unknown> = {};
protected readonly properties: Record<string, string>; protected readonly properties: Record<string, string> = {};
public constructor () {
this.properties = this.define_properties ();
}
protected abstract define_properties(): Record<string, string>;
public assign (a: Assignable): void { public assign (a: Assignable): void {
this.assign_object (a.to_object ()); this.assign_object (a.to_object ());