TSK-1153: Fix server model load exceptions (#2967)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-04-13 10:04:14 +07:00 committed by GitHub
parent 12404949d0
commit 93dd4489d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,6 +45,7 @@ import core, {
Tx,
TxCollectionCUD,
TxCreateDoc,
TxCUD,
TxMixin,
TxProcessor,
TxRemoveDoc,
@ -987,12 +988,24 @@ class MongoTxAdapter extends MongoAdapterBase implements TxAdapter {
.sort({ _id: 1 })
.toArray()
// We need to put all core.account.System transactions first
const systemTr: Tx[] = []
const systemTx: Tx[] = []
const userTx: Tx[] = []
model.forEach((tx) => (tx.modifiedBy === core.account.System ? systemTr : userTx).push(tx))
// Ignore Employee accounts.
function isEmployeeAccount (tx: Tx): boolean {
return (
(tx._class === core.class.TxCreateDoc ||
tx._class === core.class.TxUpdateDoc ||
tx._class === core.class.TxRemoveDoc) &&
(tx as TxCUD<Doc>).objectClass === 'contact:class:EmployeeAccount'
)
}
return systemTr.concat(userTx)
model.forEach((tx) =>
(tx.modifiedBy === core.account.System && !isEmployeeAccount(tx) ? systemTx : userTx).push(tx)
)
return systemTx.concat(userTx)
}
}