feat(reports): align summary aggregates
This commit is contained in:
@@ -121,6 +121,18 @@ func parseReportTimezoneOffset(c *gin.Context) (float64, bool) {
|
||||
return 0, true
|
||||
}
|
||||
|
||||
func parseOptionalReportID(c *gin.Context) (uint, bool) {
|
||||
if rawID := c.Query("id"); rawID != "" {
|
||||
parsed, err := strconv.ParseUint(rawID, 10, 64)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
|
||||
return 0, false
|
||||
}
|
||||
return uint(parsed), true
|
||||
}
|
||||
return 0, true
|
||||
}
|
||||
|
||||
func parseConversationTrafficRange(c *gin.Context) (time.Time, time.Time, float64, bool) {
|
||||
timezoneOffset, ok := parseReportTimezoneOffset(c)
|
||||
if !ok {
|
||||
@@ -210,8 +222,15 @@ func (h *AnalyticsHandler) Summary(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if _, ok := parseReportTimezoneOffset(c); !ok {
|
||||
return
|
||||
}
|
||||
id, ok := parseOptionalReportID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.GetSummary(c.Request.Context(), accountID, since, until)
|
||||
result, err := h.svc.GetReportSummary(c.Request.Context(), accountID, since, until, c.DefaultQuery("type", "account"), id, parseReportBusinessHours(c))
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Summary report: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate summary report")
|
||||
@@ -370,8 +389,12 @@ func (h *AnalyticsHandler) BotSummary(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
id, ok := parseOptionalReportID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.GetBotSummary(c.Request.Context(), accountID, since, until)
|
||||
result, err := h.svc.GetBotSummary(c.Request.Context(), accountID, since, until, c.DefaultQuery("type", "account"), id)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Bot summary report: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate bot summary")
|
||||
|
||||
Reference in New Issue
Block a user