From 75056b6e79db36ff987773b02dceee569bea1537 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Fri, 24 Nov 2023 16:01:19 +0700 Subject: [PATCH] UBERF-4374 Do not update time report for removed issues (#4059) Signed-off-by: Alexander Onnikov --- server-plugins/tracker-resources/src/index.ts | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/server-plugins/tracker-resources/src/index.ts b/server-plugins/tracker-resources/src/index.ts index eff025b23c..5b98f8bbfb 100644 --- a/server-plugins/tracker-resources/src/index.ts +++ b/server-plugins/tracker-resources/src/index.ts @@ -309,25 +309,28 @@ async function doTimeReportUpdate (cud: TxCUD, tx: Tx, control: break } case core.class.TxRemoveDoc: { - const logTxes = Array.from( - await control.findAll(core.class.TxCollectionCUD, { - 'tx.objectId': cud.objectId, - _id: { $nin: [parentTx._id] } - }) - // eslint-disable-next-line @typescript-eslint/unbound-method - ).map(TxProcessor.extractTx) - const doc: TimeSpendReport | undefined = TxProcessor.buildDoc2Doc(logTxes) - if (doc !== undefined) { - const res = [ - control.txFactory.createTxUpdateDoc(parentTx.objectClass, parentTx.objectSpace, parentTx.objectId, { - $inc: { reportedTime: -1 * doc.value } + if (!control.removedMap.has(parentTx.objectId)) { + const logTxes = Array.from( + await control.findAll(core.class.TxCollectionCUD, { + 'tx.objectId': cud.objectId, + _id: { $nin: [parentTx._id] } }) - ] - const [currentIssue] = await control.findAll(tracker.class.Issue, { _id: parentTx.objectId }, { limit: 1 }) - currentIssue.reportedTime -= doc.value - currentIssue.remainingTime = Math.max(0, currentIssue.estimation - currentIssue.reportedTime) - updateIssueParentEstimations(currentIssue, res, control, currentIssue.parents, currentIssue.parents) - return res + // eslint-disable-next-line @typescript-eslint/unbound-method + ).map(TxProcessor.extractTx) + const doc: TimeSpendReport | undefined = TxProcessor.buildDoc2Doc(logTxes) + if (doc !== undefined) { + const res = [ + control.txFactory.createTxUpdateDoc(parentTx.objectClass, parentTx.objectSpace, parentTx.objectId, { + $inc: { reportedTime: -1 * doc.value } + }) + ] + + const [currentIssue] = await control.findAll(tracker.class.Issue, { _id: parentTx.objectId }, { limit: 1 }) + currentIssue.reportedTime -= doc.value + currentIssue.remainingTime = Math.max(0, currentIssue.estimation - currentIssue.reportedTime) + updateIssueParentEstimations(currentIssue, res, control, currentIssue.parents, currentIssue.parents) + return res + } } } }