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
}
update<T extends CredentialCategory>(
update(
props: Partial<Omit<Credential<T>, 'type' | 'uuid' | 'createdAt'>>,
): Credential<T> {
const { updatedAt } = super.update(props)
const credential = new Credential<T>({ ...this, ...props, updatedAt })
return credential
return new Credential<T>({
uuid: this.uuid,
name: this.name,
avatar: this.avatar,
createdAt: this.createdAt,
category: this.category,
store: this.store,
...props,
updatedAt,
})
}
toJSON() {

View file

@ -101,8 +101,17 @@ export class Group extends Ressource {
update(props: Partial<Omit<Group, 'type' | 'uuid' | 'createdAt'>>): 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() {

View file

@ -94,8 +94,18 @@ export class Machine extends Ressource {
props: Partial<Omit<Machine, 'type' | 'uuid' | 'createdAt'>>,
): 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() {

View file

@ -85,9 +85,14 @@ export class Ressource {
update(
props: Partial<Omit<Ressource, 'type' | 'uuid' | 'createdAt'>>,
): 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() {

View file

@ -112,8 +112,18 @@ export class Service extends Ressource {
props: Partial<Omit<Service, 'type' | 'uuid' | 'createdAt'>>,
): 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() {

View file

@ -174,8 +174,20 @@ export class User extends Ressource {
update(props: Partial<Omit<User, 'type' | 'uuid' | 'createdAt'>>): 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() {