From bf6496d2179a0bc42ac72b408133e387bccbb7a5 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 13 Sep 2024 14:38:59 +0500 Subject: [PATCH] Fix account email update (#6551) Signed-off-by: Denis Bykhov --- packages/core/src/memdb.ts | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/core/src/memdb.ts b/packages/core/src/memdb.ts index 40c4e6591a..f131d6b0ca 100644 --- a/packages/core/src/memdb.ts +++ b/packages/core/src/memdb.ts @@ -263,22 +263,25 @@ export abstract class MemDb extends TxProcessor implements Storage { } updateDoc (_id: Ref, doc: Doc, update: TxUpdateDoc | TxMixin): void { - if ( - this.hierarchy.isDerived(doc._class, core.class.Account) && - update._class === core.class.TxUpdateDoc && - (update as TxUpdateDoc).operations.person !== undefined - ) { - const account = doc as Account - if (account.person !== undefined) { - const acc = this.accountByPersonId.get(account.person) ?? [] - this.accountByPersonId.set( - account.person, - acc.filter((it) => it._id !== _id) - ) - } - const newPerson = (update as TxUpdateDoc).operations.person - if (newPerson !== undefined) { - this.accountByPersonId.set(newPerson, [...(this.accountByPersonId.get(newPerson) ?? []), account]) + if (this.hierarchy.isDerived(doc._class, core.class.Account) && update._class === core.class.TxUpdateDoc) { + const newEmail = (update as TxUpdateDoc).operations.email + if ((update as TxUpdateDoc).operations.person !== undefined) { + const account = doc as Account + if (account.person !== undefined) { + const acc = this.accountByPersonId.get(account.person) ?? [] + this.accountByPersonId.set( + account.person, + acc.filter((it) => it._id !== _id) + ) + } + const newPerson = (update as TxUpdateDoc).operations.person + if (newPerson !== undefined) { + this.accountByPersonId.set(newPerson, [...(this.accountByPersonId.get(newPerson) ?? []), account]) + } + } else if (newEmail !== undefined) { + const account = doc as Account + this.accountByEmail.delete(account.email) + this.accountByEmail.set(newEmail, account) } } }