refactor: standardize frontend

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-24 17:38:48 -05:00
parent 20d3a46d7b
commit 0c4c9e52cd
24 changed files with 2448 additions and 1232 deletions

View File

@@ -16,138 +16,92 @@ export class EntityObject implements EntityInterface {
constructor() {
this._data = {
'@type': 'people:entity',
version: 1,
in: null,
id: null,
createdOn: null,
createdBy: null,
modifiedOn: null,
modifiedBy: null,
provider: '',
service: '',
collection: '',
identifier: '',
signature: null,
data: null,
created: null,
modified: null,
properties: new IndividualObject(),
};
}
fromJson(data: EntityInterface) : EntityObject {
this._data = data;
if (data.data) {
const type = data.data.type;
if (data.properties) {
const type = data.properties.type;
if (type === 'organization') {
this._data.data = new OrganizationObject().fromJson(data.data as OrganizationInterface);
this._data.properties = new OrganizationObject().fromJson(data.properties as OrganizationInterface);
} else if (type === 'group') {
this._data.data = new GroupObject().fromJson(data.data as GroupInterface);
this._data.properties = new GroupObject().fromJson(data.properties as GroupInterface);
} else {
this._data.data = new IndividualObject().fromJson(data.data as IndividualInterface);
this._data.properties = new IndividualObject().fromJson(data.properties as IndividualInterface);
}
} else {
this._data.data = null;
}
return this;
}
toJson(): EntityInterface {
const json = { ...this._data };
if (this._data.data instanceof IndividualObject ||
this._data.data instanceof OrganizationObject ||
this._data.data instanceof GroupObject) {
json.data = this._data.data.toJson();
if (this._data.properties instanceof IndividualObject ||
this._data.properties instanceof OrganizationObject ||
this._data.properties instanceof GroupObject) {
json.properties = this._data.properties.toJson();
}
return json;
}
clone(): EntityObject {
const cloned = new EntityObject()
cloned._data = JSON.parse(JSON.stringify(this._data))
return cloned
const cloned = new EntityObject();
cloned._data = { ...this._data };
return cloned;
}
/** Immutable Properties */
get '@type'(): string {
return this._data['@type'];
get provider(): string {
return this._data.provider;
}
get in(): number | string | null {
return this._data.in;
get service(): string {
return this._data.service;
}
get id(): number | string | null {
return this._data.id;
get collection(): string | number {
return this._data.collection;
}
get version(): number {
return this._data.version;
}
get createdOn(): Date | null {
return this._data.createdOn;
}
get createdBy(): string | null {
return this._data.createdBy;
}
get modifiedOn(): Date | null {
return this._data.modifiedOn;
}
get modifiedBy(): string | null {
return this._data.modifiedBy;
get identifier(): string | number {
return this._data.identifier;
}
get signature(): string | null {
return this._data.signature;
}
/** Mutable Properties */
set createdOn(value: Date | null) {
this._data.createdOn = value;
get created(): string | null {
return this._data.created;
}
set createdBy(value: string | null) {
this._data.createdBy = value;
get modified(): string | null {
return this._data.modified;
}
set modifiedOn(value: Date | null) {
this._data.modifiedOn = value;
}
set modifiedBy(value: string | null) {
this._data.modifiedBy = value;
}
set signature(value: string | null) {
this._data.signature = value;
}
get data(): IndividualObject | OrganizationObject | GroupObject | null {
if (this._data.data instanceof IndividualObject ||
this._data.data instanceof OrganizationObject ||
this._data.data instanceof GroupObject) {
return this._data.data;
get properties(): IndividualObject | OrganizationObject | GroupObject {
if (this._data.properties instanceof IndividualObject ||
this._data.properties instanceof OrganizationObject ||
this._data.properties instanceof GroupObject) {
return this._data.properties;
}
if (this._data.data) {
const type = this._data.data.type;
let hydrated;
if (type === 'organization') {
hydrated = new OrganizationObject().fromJson(this._data.data as OrganizationInterface);
} else if (type === 'group') {
hydrated = new GroupObject().fromJson(this._data.data as GroupInterface);
} else {
hydrated = new IndividualObject().fromJson(this._data.data as IndividualInterface);
}
this._data.data = hydrated;
return hydrated;
}
return null;
const defaultProperties = new IndividualObject();
this._data.properties = defaultProperties;
return defaultProperties;
}
set data(value: IndividualObject | OrganizationObject | GroupObject | null) {
this._data.data = value;
set properties(value: IndividualObject | OrganizationObject | GroupObject) {
this._data.properties = value;
}
}