Skip to content
2 changes: 2 additions & 0 deletions apps/customer-portal/backend/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const ERR_MSG_CASE_ID_EMPTY = "Case ID cannot be empty!";
const ERR_LIMIT_OFFSET_INVALID = "Limit must be between 1 and 50. Offset must be a non-negative integer!";
const ERR_MSG_UNAUTHORIZED_ACCESS = "You're not authorized to access this service. Please sign in again. " +
"If the issue continues, contact support.";
const ERR_MSG_CASES_STATISTICS = "Failed to retrieve project case statistics.";
const ERR_MSG_CHATS_STATISTICS = "Failed to retrieve project chat statistics.";

// Default Pagination Values
public const int DEFAULT_OFFSET = 0;
Expand Down
8 changes: 7 additions & 1 deletion apps/customer-portal/backend/modules/entity/entity.bal
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ public isolated function getProjectActivityStats(string idToken, string id) retu
#
# + idToken - ID token for authorization
# + id - Unique ID of the project
# + caseTypes - Optional array of case types to filter statistics
# + return - Project cases statistics or error
public isolated function getCaseStatsForProject(string idToken, string id) returns ProjectCaseStatsResponse|error {
public isolated function getCaseStatsForProject(string idToken, string id, string[]? caseTypes)
returns ProjectCaseStatsResponse|error {

if caseTypes is string[] {
return csEntityClient->/projects/[id]/cases/stats.get(generateHeaders(idToken), caseTypes = caseTypes);
}
return csEntityClient->/projects/[id]/cases/stats.get(generateHeaders(idToken));
}
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved

Expand Down
46 changes: 32 additions & 14 deletions apps/customer-portal/backend/modules/entity/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ public type Case record {|

# Choice list item information.
public type ChoiceListItem record {|
# ID
# Choice list item value
int id;
# Label
# Choice list item label
string label;
# Count
int count?;
json...;
|};

Expand All @@ -216,19 +218,23 @@ public type ReferenceTableItem record {|
string id;
# Display name
string name;
# Count value
int count?;
json...;
|};

# Case search filters.
public type CaseSearchFilters record {|
# List of project IDs to filter
string[] projectIds?;
# List of case type IDs to filter
string[] caseTypeIds?;
# Search query for case number, title and description
string searchQuery?;
# List of issue types to filter
int[] issueTypeKeys?;
# State key
int stateKey?;
int[] stateKeys?;
# Severity key
int severityKey?;
# Deployment ID
Expand Down Expand Up @@ -289,6 +295,7 @@ public type SortBy record {|
CaseSortField 'field;
# Sort order
SortOrder 'order;
json...;
|};

# Project metadata response.
Expand Down Expand Up @@ -317,13 +324,11 @@ public type ProjectMetadataResponse record {|
# Project statistics response from ServiceNow.
public type ProjectStatsResponse record {|
# Total time logged
decimal totalTimeLogged;
decimal totalTimeLogged?;
# Billable hours
decimal billableHours;
# System health status
string systemHealth;
decimal billableHours?;
# SLA status
string slaStatus;
string slaStatus?;
json...;
|};

Expand Down Expand Up @@ -362,20 +367,33 @@ public type ResolvedCaseCount record {|
json...;
|};

# Cases trend by time unit.
public type CasesTrend record {|
# Time unit identifier (e.g., "2025 - Q1", "2025 - M1")
string period;
# Severity breakdown for the time unit
ChoiceListItem[] severities;
json...;
|};

# Project cases statistics response.
public type ProjectCaseStatsResponse record {|
# Total case count
int totalCount;
# Open case count
int openCount;
# Average response time
decimal averageResponseTime;
# Active case count breakdown
ActiveCaseCount activeCount;
# Outstanding cases count breakdown
OutstandingCasesCount outstandingCasesCount;
# Resolved case count breakdown
ResolvedCaseCount resolvedCount;
# Count of cases by state
ChoiceListItem[] stateCount;
# Count of cases by severity
ChoiceListItem[] severityCount;
# Outstanding cases count by severity
ChoiceListItem[] outstandingSeverityCount;
# Count of cases by type
ReferenceTableItem[] caseTypeCount;
# Cases trend
CasesTrend[] casesTrend;
json...;
|};

Expand Down
48 changes: 27 additions & 21 deletions apps/customer-portal/backend/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public type CaseSearchFilters record {|
string searchQuery?;
# Issue ID
int issueId?;
# Status ID
int statusId?;
# Status IDs
int[] statusIds?;
# List of case type IDs
string[] caseTypeIds?;
# Severity ID
int severityId?;
# Deployment ID
Expand Down Expand Up @@ -91,6 +93,8 @@ public type ReferenceItem record {|
string id;
# Label
string label;
# Count
int count?;
|};

# Cases list response with pagination.
Expand Down Expand Up @@ -157,52 +161,54 @@ public type ProjectFilterOptions record {|
public type ProjectCaseStats record {|
# Total case count
int totalCases;
# Open cases count
int openCases;
# Average response time
decimal averageResponseTime;
# Active case count breakdown
entity:ActiveCaseCount activeCases;
# Outstanding cases count breakdown
entity:OutstandingCasesCount outstandingCases;
# Resolved case count breakdown
entity:ResolvedCaseCount resolvedCases;
# Count of cases by state
ReferenceItem[] stateCount;
# Count of cases by severity
ReferenceItem[] severityCount;
# Outstanding cases count by severity
ReferenceItem[] outstandingSeverityCount;
# Count of cases by type
ReferenceItem[] caseTypeCount;
# Cases trend
entity:CasesTrend[] casesTrend;
|};

# Project support statistics.
public type ProjectSupportStats record {|
# Total cases count
int totalCases;
int totalCases?;
# Active chats count
int activeChats;
int activeChats?;
# Session chats count
int sessionChats;
int sessionChats?;
# Resolved chats count
int resolvedChats;
int resolvedChats?;
|};

# Project statistics.
public type ProjectStats record {|
# Open cases count
int openCases;
int openCases?;
# Active chats count
int activeChats;
int activeChats?;
# Deployments count
int deployments;
int deployments?;
# SLA status
string slaStatus;
string slaStatus?;
|};

# Recent activity details.
public type RecentActivity record {|
# Total time logged
decimal totalTimeLogged;
decimal totalTimeLogged?;
# Billable hours
decimal billableHours;
decimal billableHours?;
# Last deployment date
string? lastDeploymentOn;
# System health status
string systemHealth;
string? lastDeploymentOn?;
|};

# Project statistics response.
Expand Down
Loading