refactor: minor code cleanup
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,11 +9,11 @@ import type {
|
|||||||
CollectionPropertiesInterface,
|
CollectionPropertiesInterface,
|
||||||
CollectionPropertiesModelInterface
|
CollectionPropertiesModelInterface
|
||||||
} from "@/types/collection";
|
} from "@/types/collection";
|
||||||
import { clonePlain } from './clone-plain';
|
|
||||||
import type {
|
import type {
|
||||||
CollectionIdentifier,
|
CollectionIdentifier,
|
||||||
ServiceIdentifier
|
ServiceIdentifier
|
||||||
} from "@/types/common";
|
} from "@/types/common";
|
||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
export class CollectionObject implements CollectionModelInterface {
|
export class CollectionObject implements CollectionModelInterface {
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ export class CollectionObject implements CollectionModelInterface {
|
|||||||
service: '' as ServiceIdentifier,
|
service: '' as ServiceIdentifier,
|
||||||
collection: null as CollectionIdentifier | null,
|
collection: null as CollectionIdentifier | null,
|
||||||
identifier: '' as CollectionIdentifier,
|
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 {
|
toJson(): CollectionInterface {
|
||||||
const json = this._properties
|
const json = this._properties
|
||||||
? {
|
? { ...this._data, properties: this._properties.toJson() }
|
||||||
...this._data,
|
|
||||||
properties: this._properties.toJson(),
|
|
||||||
}
|
|
||||||
: this._data;
|
: this._data;
|
||||||
|
|
||||||
return clonePlain(json);
|
return clonePlain(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +79,8 @@ export class CollectionObject implements CollectionModelInterface {
|
|||||||
return this._data.modified;
|
return this._data.modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mutable Properties */
|
||||||
|
|
||||||
get properties(): CollectionPropertiesObject {
|
get properties(): CollectionPropertiesObject {
|
||||||
if (this._properties) {
|
if (this._properties) {
|
||||||
return this._properties;
|
return this._properties;
|
||||||
|
|||||||
+10
-17
@@ -12,10 +12,12 @@ import { OrganizationObject } from "./organization";
|
|||||||
import { GroupObject } from "./group";
|
import { GroupObject } from "./group";
|
||||||
import { clonePlain } from './clone-plain';
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
|
export type EntityPropertiesObject = IndividualObject | OrganizationObject | GroupObject;
|
||||||
|
|
||||||
export class EntityObject implements EntityModelInterface {
|
export class EntityObject implements EntityModelInterface {
|
||||||
|
|
||||||
private _data!: EntityInterface<EntityPropertiesInterface>;
|
private _data!: EntityInterface<EntityPropertiesInterface>;
|
||||||
private _properties: IndividualObject | OrganizationObject | GroupObject | undefined = undefined;
|
private _properties: EntityPropertiesObject | undefined = undefined;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
@@ -40,12 +42,8 @@ export class EntityObject implements EntityModelInterface {
|
|||||||
|
|
||||||
toJson(): EntityInterface {
|
toJson(): EntityInterface {
|
||||||
const json = this._properties
|
const json = this._properties
|
||||||
? {
|
? { ...this._data, properties: this._properties.toJson() }
|
||||||
...this._data,
|
|
||||||
properties: this._properties.toJson(),
|
|
||||||
}
|
|
||||||
: this._data;
|
: this._data;
|
||||||
|
|
||||||
return clonePlain(json);
|
return clonePlain(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,17 +83,13 @@ export class EntityObject implements EntityModelInterface {
|
|||||||
|
|
||||||
/** Entity Properties (individual | organization | group) */
|
/** Entity Properties (individual | organization | group) */
|
||||||
|
|
||||||
get properties(): IndividualObject | OrganizationObject | GroupObject {
|
get properties(): EntityPropertiesObject {
|
||||||
if (this._properties) {
|
if (this._properties) return this._properties;
|
||||||
return this._properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
const raw = this._data.properties as EntityPropertiesInterface;
|
const raw = this._data.properties;
|
||||||
const type = (raw as { type?: string })?.type;
|
if (raw.type === 'organization') {
|
||||||
|
|
||||||
if (type === 'organization') {
|
|
||||||
this._properties = new OrganizationObject().fromJson(raw as OrganizationInterface);
|
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);
|
this._properties = new GroupObject().fromJson(raw as GroupInterface);
|
||||||
} else {
|
} else {
|
||||||
this._properties = new IndividualObject().fromJson(raw as IndividualInterface);
|
this._properties = new IndividualObject().fromJson(raw as IndividualInterface);
|
||||||
@@ -104,8 +98,7 @@ export class EntityObject implements EntityModelInterface {
|
|||||||
return this._properties;
|
return this._properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
set properties(value: IndividualObject | OrganizationObject | GroupObject) {
|
set properties(value: EntityPropertiesObject) {
|
||||||
this._properties = value;
|
this._properties = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user