refactor: minor code cleanup

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-28 12:22:15 -04:00
parent 5fbc217edb
commit 85faaa3747
2 changed files with 15 additions and 24 deletions
+5 -7
View File
@@ -9,11 +9,11 @@ import type {
CollectionPropertiesInterface,
CollectionPropertiesModelInterface
} from "@/types/collection";
import { clonePlain } from './clone-plain';
import type {
CollectionIdentifier,
ServiceIdentifier
} from "@/types/common";
import { clonePlain } from './clone-plain';
export class CollectionObject implements CollectionModelInterface {
@@ -28,7 +28,7 @@ export class CollectionObject implements CollectionModelInterface {
service: '' as ServiceIdentifier,
collection: null as CollectionIdentifier | null,
identifier: '' as CollectionIdentifier,
properties: { '@type': 'people:addressbook', content: [], label: '', description: null, rank: null, visibility: null, color: null },
properties: new CollectionPropertiesObject().toJson(),
};
}
@@ -40,12 +40,8 @@ export class CollectionObject implements CollectionModelInterface {
toJson(): CollectionInterface {
const json = this._properties
? {
...this._data,
properties: this._properties.toJson(),
}
? { ...this._data, properties: this._properties.toJson() }
: this._data;
return clonePlain(json);
}
@@ -83,6 +79,8 @@ export class CollectionObject implements CollectionModelInterface {
return this._data.modified;
}
/** Mutable Properties */
get properties(): CollectionPropertiesObject {
if (this._properties) {
return this._properties;
+10 -17
View File
@@ -12,10 +12,12 @@ import { OrganizationObject } from "./organization";
import { GroupObject } from "./group";
import { clonePlain } from './clone-plain';
export type EntityPropertiesObject = IndividualObject | OrganizationObject | GroupObject;
export class EntityObject implements EntityModelInterface {
private _data!: EntityInterface<EntityPropertiesInterface>;
private _properties: IndividualObject | OrganizationObject | GroupObject | undefined = undefined;
private _properties: EntityPropertiesObject | undefined = undefined;
constructor() {
this._data = {
@@ -40,12 +42,8 @@ export class EntityObject implements EntityModelInterface {
toJson(): EntityInterface {
const json = this._properties
? {
...this._data,
properties: this._properties.toJson(),
}
? { ...this._data, properties: this._properties.toJson() }
: this._data;
return clonePlain(json);
}
@@ -85,17 +83,13 @@ export class EntityObject implements EntityModelInterface {
/** Entity Properties (individual | organization | group) */
get properties(): IndividualObject | OrganizationObject | GroupObject {
if (this._properties) {
return this._properties;
}
get properties(): EntityPropertiesObject {
if (this._properties) return this._properties;
const raw = this._data.properties as EntityPropertiesInterface;
const type = (raw as { type?: string })?.type;
if (type === 'organization') {
const raw = this._data.properties;
if (raw.type === 'organization') {
this._properties = new OrganizationObject().fromJson(raw as OrganizationInterface);
} else if (type === 'group') {
} else if (raw.type === 'group') {
this._properties = new GroupObject().fromJson(raw as GroupInterface);
} else {
this._properties = new IndividualObject().fromJson(raw as IndividualInterface);
@@ -104,8 +98,7 @@ export class EntityObject implements EntityModelInterface {
return this._properties;
}
set properties(value: IndividualObject | OrganizationObject | GroupObject) {
set properties(value: EntityPropertiesObject) {
this._properties = value;
}
}