fix(model): 🐛 destructuration in update method is invalid due to getters

This commit is contained in:
Julien Oculi 2024-06-24 13:42:32 +02:00
parent ae7b911b16
commit 9bb122f813
6 changed files with 68 additions and 14 deletions

View file

@ -73,12 +73,20 @@ export class Credential<T extends CredentialCategory> extends Ressource {
return this.#store return this.#store
} }
update<T extends CredentialCategory>( update(
props: Partial<Omit<Credential<T>, 'type' | 'uuid' | 'createdAt'>>, props: Partial<Omit<Credential<T>, 'type' | 'uuid' | 'createdAt'>>,
): Credential<T> { ): Credential<T> {
const { updatedAt } = super.update(props) const { updatedAt } = super.update(props)
const credential = new Credential<T>({ ...this, ...props, updatedAt }) return new Credential<T>({
return credential uuid: this.uuid,
name: this.name,
avatar: this.avatar,
createdAt: this.createdAt,
category: this.category,
store: this.store,
...props,
updatedAt,
})
} }
toJSON() { toJSON() {

View file

@ -101,8 +101,17 @@ export class Group extends Ressource {
update(props: Partial<Omit<Group, 'type' | 'uuid' | 'createdAt'>>): Group { update(props: Partial<Omit<Group, 'type' | 'uuid' | 'createdAt'>>): Group {
const { updatedAt } = super.update(props) const { updatedAt } = super.update(props)
const group = new Group({ ...this, ...props, updatedAt }) return new Group({
return 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() { toJSON() {

View file

@ -94,8 +94,18 @@ export class Machine extends Ressource {
props: Partial<Omit<Machine, 'type' | 'uuid' | 'createdAt'>>, props: Partial<Omit<Machine, 'type' | 'uuid' | 'createdAt'>>,
): Machine { ): Machine {
const { updatedAt } = super.update(props) const { updatedAt } = super.update(props)
const machine = new Machine({ ...this, ...props, updatedAt }) return new Machine({
return 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() { toJSON() {

View file

@ -85,9 +85,14 @@ export class Ressource {
update( update(
props: Partial<Omit<Ressource, 'type' | 'uuid' | 'createdAt'>>, props: Partial<Omit<Ressource, 'type' | 'uuid' | 'createdAt'>>,
): Ressource { ): Ressource {
const updated = new Ressource({ ...this, ...props }) return new Ressource({
updated.#updatedAt = new Date().toISOString() as DateString name: this.name,
return updated avatar: this.avatar,
uuid: this.uuid,
createdAt: this.createdAt,
updatedAt: new Date().toISOString() as DateString,
...props,
})
} }
toJSON() { toJSON() {

View file

@ -112,8 +112,18 @@ export class Service extends Ressource {
props: Partial<Omit<Service, 'type' | 'uuid' | 'createdAt'>>, props: Partial<Omit<Service, 'type' | 'uuid' | 'createdAt'>>,
): Service { ): Service {
const { updatedAt } = super.update(props) const { updatedAt } = super.update(props)
const service = new Service({ ...this, ...props, updatedAt }) return new Service({
return 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() { toJSON() {

View file

@ -174,8 +174,20 @@ export class User extends Ressource {
update(props: Partial<Omit<User, 'type' | 'uuid' | 'createdAt'>>): User { update(props: Partial<Omit<User, 'type' | 'uuid' | 'createdAt'>>): User {
const { updatedAt } = super.update(props) const { updatedAt } = super.update(props)
const user = new User({ ...this, ...props, updatedAt }) return new User({
return 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() { toJSON() {