From 9bb122f81385657a684f595241e7c0aed5b96bd8 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Mon, 24 Jun 2024 13:42:32 +0200 Subject: [PATCH] fix(model): :bug: destructuration in `update` method is invalid due to getters --- src/models/src/credential.ts | 14 +++++++++++--- src/models/src/group.ts | 13 +++++++++++-- src/models/src/machine.ts | 14 ++++++++++++-- src/models/src/ressource.ts | 11 ++++++++--- src/models/src/service.ts | 14 ++++++++++++-- src/models/src/user.ts | 16 ++++++++++++++-- 6 files changed, 68 insertions(+), 14 deletions(-) diff --git a/src/models/src/credential.ts b/src/models/src/credential.ts index 1e149e6..2722e7c 100644 --- a/src/models/src/credential.ts +++ b/src/models/src/credential.ts @@ -73,12 +73,20 @@ export class Credential extends Ressource { return this.#store } - update( + update( props: Partial, 'type' | 'uuid' | 'createdAt'>>, ): Credential { const { updatedAt } = super.update(props) - const credential = new Credential({ ...this, ...props, updatedAt }) - return credential + return new Credential({ + uuid: this.uuid, + name: this.name, + avatar: this.avatar, + createdAt: this.createdAt, + category: this.category, + store: this.store, + ...props, + updatedAt, + }) } toJSON() { diff --git a/src/models/src/group.ts b/src/models/src/group.ts index 49e9512..1174aac 100644 --- a/src/models/src/group.ts +++ b/src/models/src/group.ts @@ -101,8 +101,17 @@ export class Group extends Ressource { update(props: Partial>): Group { const { updatedAt } = super.update(props) - const group = new Group({ ...this, ...props, updatedAt }) - return group + return new Group({ + uuid: this.uuid, + name: this.name, + avatar: this.avatar, + createdAt: this.createdAt, + posix: this.posix, + permissions: this.permissions, + groups: this.groups, + ...props, + updatedAt, + }) } toJSON() { diff --git a/src/models/src/machine.ts b/src/models/src/machine.ts index 53232c8..9cae7e7 100644 --- a/src/models/src/machine.ts +++ b/src/models/src/machine.ts @@ -94,8 +94,18 @@ export class Machine extends Ressource { props: Partial>, ): Machine { const { updatedAt } = super.update(props) - const machine = new Machine({ ...this, ...props, updatedAt }) - return machine + return new Machine({ + uuid: this.uuid, + name: this.name, + avatar: this.avatar, + createdAt: this.createdAt, + tags: this.tags, + url: this.url, + status: this.status, + groups: this.groups, + ...props, + updatedAt, + }) } toJSON() { diff --git a/src/models/src/ressource.ts b/src/models/src/ressource.ts index 4ae58c4..a903833 100644 --- a/src/models/src/ressource.ts +++ b/src/models/src/ressource.ts @@ -85,9 +85,14 @@ export class Ressource { update( props: Partial>, ): Ressource { - const updated = new Ressource({ ...this, ...props }) - updated.#updatedAt = new Date().toISOString() as DateString - return updated + return new Ressource({ + name: this.name, + avatar: this.avatar, + uuid: this.uuid, + createdAt: this.createdAt, + updatedAt: new Date().toISOString() as DateString, + ...props, + }) } toJSON() { diff --git a/src/models/src/service.ts b/src/models/src/service.ts index f3a2ee7..b8130eb 100644 --- a/src/models/src/service.ts +++ b/src/models/src/service.ts @@ -112,8 +112,18 @@ export class Service extends Ressource { props: Partial>, ): Service { const { updatedAt } = super.update(props) - const service = new Service({ ...this, ...props, updatedAt }) - return service + return new Service({ + uuid: this.uuid, + name: this.name, + createdAt: this.createdAt, + avatar: this.avatar, + category: this.category, + url: this.url, + tags: this.tags, + groups: this.groups, + ...props, + updatedAt, + }) } toJSON() { diff --git a/src/models/src/user.ts b/src/models/src/user.ts index d3588b6..7613f81 100644 --- a/src/models/src/user.ts +++ b/src/models/src/user.ts @@ -174,8 +174,20 @@ export class User extends Ressource { update(props: Partial>): User { const { updatedAt } = super.update(props) - const user = new User({ ...this, ...props, updatedAt }) - return user + return new User({ + uuid: this.uuid, + name: this.name, + avatar: this.avatar, + createdAt: this.createdAt, + lastname: this.lastname, + firstname: this.firstname, + mail: this.mail, + groups: this.groups, + posix: this.posix, + credentials: this.credentials, + ...props, + updatedAt, + }) } toJSON() {