feat(reports): align v2 report envelopes
This commit is contained in:
@@ -54,7 +54,7 @@ func (h *AnalyticsHandler) Index(c *gin.Context) {
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate report")
|
||||
return
|
||||
}
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// parseAccountID extracts account_id from URL params.
|
||||
@@ -77,13 +77,13 @@ func parseDateRange(c *gin.Context) (since, until time.Time, ok bool) {
|
||||
return time.Time{}, time.Time{}, false
|
||||
}
|
||||
|
||||
since, err := time.Parse(time.RFC3339, sinceStr)
|
||||
since, err := parseChatwootReportTime(sinceStr)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid since date format")
|
||||
return time.Time{}, time.Time{}, false
|
||||
}
|
||||
|
||||
until, err = time.Parse(time.RFC3339, untilStr)
|
||||
until, err = parseChatwootReportTime(untilStr)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid until date format")
|
||||
return time.Time{}, time.Time{}, false
|
||||
@@ -92,6 +92,14 @@ func parseDateRange(c *gin.Context) (since, until time.Time, ok bool) {
|
||||
return since, until, true
|
||||
}
|
||||
|
||||
func parseChatwootReportTime(value string) (time.Time, error) {
|
||||
if unixSeconds, err := strconv.ParseInt(value, 10, 64); err == nil {
|
||||
return time.Unix(unixSeconds, 0).UTC(), nil
|
||||
}
|
||||
|
||||
return time.Parse(time.RFC3339, value)
|
||||
}
|
||||
|
||||
// Summary returns account-level aggregated metrics.
|
||||
// GET /api/v1/accounts/:account_id/reports/summary
|
||||
func (h *AnalyticsHandler) Summary(c *gin.Context) {
|
||||
@@ -111,7 +119,7 @@ func (h *AnalyticsHandler) Summary(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// AgentMetrics returns metrics grouped by agent.
|
||||
@@ -133,7 +141,7 @@ func (h *AnalyticsHandler) AgentMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// InboxMetrics returns metrics grouped by inbox.
|
||||
@@ -155,7 +163,7 @@ func (h *AnalyticsHandler) InboxMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// LabelMetrics returns metrics grouped by label.
|
||||
@@ -177,7 +185,7 @@ func (h *AnalyticsHandler) LabelMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// TeamMetrics returns metrics grouped by team.
|
||||
@@ -199,7 +207,7 @@ func (h *AnalyticsHandler) TeamMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// ConversationTraffic returns daily conversation traffic time-series.
|
||||
@@ -221,7 +229,7 @@ func (h *AnalyticsHandler) ConversationTraffic(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// BotSummary returns bot-level summary metrics.
|
||||
@@ -244,7 +252,7 @@ func (h *AnalyticsHandler) BotSummary(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// Conversations returns conversation metrics filtered by type.
|
||||
@@ -270,7 +278,7 @@ func (h *AnalyticsHandler) Conversations(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// ConversationsSummary returns conversation summary report.
|
||||
@@ -293,7 +301,7 @@ func (h *AnalyticsHandler) ConversationsSummary(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// BotMetrics returns bot metrics.
|
||||
@@ -316,7 +324,7 @@ func (h *AnalyticsHandler) BotMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// InboxLabelMatrix returns inbox-label matrix data.
|
||||
@@ -335,7 +343,7 @@ func (h *AnalyticsHandler) InboxLabelMatrix(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// FirstResponseTimeDistribution returns first response time distribution.
|
||||
@@ -358,7 +366,7 @@ func (h *AnalyticsHandler) FirstResponseTimeDistribution(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// OutgoingMessagesCount returns outgoing message count metrics.
|
||||
@@ -386,5 +394,5 @@ func (h *AnalyticsHandler) OutgoingMessagesCount(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, result)
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user