export default class HostRecord { public value = ''; public type: 'paragraph'|'database_ref'|'code_ref'|'file_ref' = 'paragraph'; public CreatedAt: string; public PageId: string; private privUUID: string; public UpdatedAt: string; public Value: any; public get UUID(): string { return this.privUUID; } public set UUID(val: string) {} constructor(value = '') { this.value = value; } public isNorm() { return ['paragraph', 'header1', 'header2', 'header3', 'header4', 'block_code', 'click_link', 'page_sep'].includes(this.type); } load(data: any) { this.type = data.Type; this.privUUID = data.UUID; [ 'CreatedAt', 'PageId', 'UpdatedAt', 'Value', ].forEach(field => { if ( field in data ) { this[field] = data[field]; } }); } toSave() { const data: any = { Type: this.type }; [ 'CreatedAt', 'PageId', 'UUID', 'UpdatedAt', 'Value', ].forEach(field => { if ( field in this ) { data[field] = this[field]; } }); if ( !data.Value ) { data.Value = {}; } data.Value.Value = this.value; return data; } }