From 1fbaf0707b6dc31962f15f710879408fddda18d2 Mon Sep 17 00:00:00 2001 From: sdjdd Date: Thu, 22 Feb 2024 12:27:35 +0800 Subject: [PATCH] feat(next): [stats] ingnore new replies after ticket closed --- next/api/src/cloud/ticketStats/utils.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/next/api/src/cloud/ticketStats/utils.ts b/next/api/src/cloud/ticketStats/utils.ts index f56ec7722..fc8e36538 100644 --- a/next/api/src/cloud/ticketStats/utils.ts +++ b/next/api/src/cloud/ticketStats/utils.ts @@ -140,8 +140,11 @@ export const getTicketDataById = async (id: string, endDate: Date) => { cursor?: typeof cursor; }> = []; timeLine.forEach((replyOrOpsLog) => { + const lastLifeLog = _.last(lifeLogs); + const ticketClosed = + !!lastLifeLog && (lastLifeLog.action === 'close' || lastLifeLog.action === 'resolve'); + if (_isOpsLog(replyOrOpsLog)) { - const lastTimeLog = _.last(lifeLogs); switch (replyOrOpsLog.action) { case 'selectAssignee': case 'changeAssignee': @@ -157,7 +160,7 @@ export const getTicketDataById = async (id: string, endDate: Date) => { authorId: replyOrOpsLog.data?.operator?.objectId, createdAt: replyOrOpsLog.createdAt, cursor: - !!replyOrOpsLog.internal || cursor.lastReplyType === 'customerService' + !!replyOrOpsLog.internal || cursor.lastReplyType === 'customerService' || ticketClosed ? undefined : { ...cursor, @@ -167,12 +170,12 @@ export const getTicketDataById = async (id: string, endDate: Date) => { break; case 'resolve': case 'close': - if (!lastTimeLog || lastTimeLog.action === 'reopen') { + if (!ticketClosed) { lifeLogs.push(replyOrOpsLog); } break; case 'reopen': - if (lastTimeLog && (lastTimeLog.action === 'close' || lastTimeLog.action === 'resolve')) { + if (ticketClosed) { lifeLogs.push(replyOrOpsLog); } if (_getReplyOrOpsLogType(replyOrOpsLog, ticket.authorId) === 'staff') { @@ -196,7 +199,7 @@ export const getTicketDataById = async (id: string, endDate: Date) => { authorId: replyOrOpsLog.authorId, createdAt: replyOrOpsLog.createdAt, cursor: - !!replyOrOpsLog.internal || cursor.lastReplyType === 'customerService' + !!replyOrOpsLog.internal || cursor.lastReplyType === 'customerService' || ticketClosed ? undefined : { ...cursor,