UBER-174: Introduce createOn every there (#3222)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2023-05-20 00:37:22 +07:00
committed by GitHub
parent 0f62a3175e
commit c0bb68be9e
50 changed files with 159 additions and 317 deletions
+2 -28
View File
@@ -13,16 +13,7 @@
// limitations under the License.
//
import core, {
AttachedDoc,
Doc,
MeasureContext,
ServerStorage,
Timestamp,
Tx,
TxCollectionCUD,
TxCreateDoc
} from '@hcengineering/core'
import core, { MeasureContext, ServerStorage, Tx } from '@hcengineering/core'
import { BroadcastFunc, Middleware, SessionContext, TxMiddlewareResult } from '@hcengineering/server-core'
import { BaseMiddleware } from './base'
@@ -46,24 +37,7 @@ export class ModifiedMiddleware extends BaseMiddleware implements Middleware {
async tx (ctx: SessionContext, tx: Tx): Promise<TxMiddlewareResult> {
if (tx.modifiedBy !== core.account.System) {
tx.modifiedOn = Date.now()
if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCreateDoc)) {
const createTx = tx as TxCreateDoc<Doc & { createOn: Timestamp }>
const hasCreateOn = this.storage.hierarchy.findAttribute(createTx.objectClass, 'createOn')
if (hasCreateOn !== undefined) {
createTx.attributes.createOn = tx.modifiedOn
}
}
if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCollectionCUD)) {
const coltx = tx as TxCollectionCUD<Doc, AttachedDoc>
coltx.tx.modifiedOn = tx.modifiedOn
if (this.storage.hierarchy.isDerived(coltx.tx._class, core.class.TxCreateDoc)) {
const createTx = coltx.tx as TxCreateDoc<AttachedDoc & { createOn: Timestamp }>
const hasCreateOn = this.storage.hierarchy.findAttribute(createTx.objectClass, 'createOn')
if (hasCreateOn !== undefined) {
createTx.attributes.createOn = tx.modifiedOn
}
}
}
tx.createOn = tx.createOn ?? tx.modifiedOn
}
return await this.provideTx(ctx, tx)
}