Remove member when delete contact (#2673)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-02-21 19:45:05 +06:00 committed by GitHub
parent dae9de4800
commit 9a96035b00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ import { workbenchId } from '@hcengineering/workbench'
*/ */
export async function OnContactDelete ( export async function OnContactDelete (
tx: Tx, tx: Tx,
{ findAll, hierarchy, storageFx, removedMap }: TriggerControl { findAll, hierarchy, storageFx, removedMap, txFactory }: TriggerControl
): Promise<Tx[]> { ): Promise<Tx[]> {
if (tx._class !== core.class.TxRemoveDoc) { if (tx._class !== core.class.TxRemoveDoc) {
return [] return []
@ -66,7 +66,22 @@ export async function OnContactDelete (
} }
}) })
return [] const result: Tx[] = []
const members = await findAll(contact.class.Member, { contact: removeContact._id })
for (const member of members) {
const removeTx = txFactory.createTxRemoveDoc(member._class, member.space, member._id)
const tx = txFactory.createTxCollectionCUD(
member.attachedToClass,
member.attachedTo,
member.space,
member.collection,
removeTx
)
result.push(tx)
}
return result
} }
/** /**