Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions apps/customer-portal/backend/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ modules = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.10.1"
version = "2.9.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand Down Expand Up @@ -265,7 +265,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.6.0"
version = "1.5.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -282,11 +282,10 @@ dependencies = [
[[package]]
org = "ballerina"
name = "task"
version = "2.11.1"
version = "2.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"},
{org = "ballerina", name = "uuid"}
{org = "ballerina", name = "time"}
]

[[package]]
Expand Down Expand Up @@ -322,17 +321,6 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "uuid"
version = "1.10.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "time"}
]

[[package]]
org = "ballerinai"
name = "observe"
Expand Down
8 changes: 8 additions & 0 deletions apps/customer-portal/backend/modules/entity/enums.bal
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ public enum ConversationSortField {
CONVERSATION_CREATED_ON = "createdOn",
CONVERSATION_UPDATED_ON = "updatedOn"
}

# Case type enum
public enum CaseType {
DEFAULT_CASE = "default_case",
SERVICE_REQUEST = "service_request",
SECURITY_REPORT_ANALYSIS = "security_report_analysis",
ANNOUNCEMENT = "announcement"
}
44 changes: 30 additions & 14 deletions apps/customer-portal/backend/modules/entity/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,32 @@ public type ProjectResponse record {|

# Payload for creating a case.
public type CaseCreatePayload record {|
# Case type
CaseType caseType?;
# Project ID
IdString projectId;
# Deployment ID
IdString deploymentId;
# Product ID
IdString productId;
# Case title
@constraint:String {minLength: 1, maxLength: 500}
string title;
# Case description
@constraint:String {minLength: 1}
string description;
# Issue type ID
int issueTypeKey;
# Severity key
int severityKey;
# Deployed product ID
IdString deployedProductId?; // TODO: Need to update as a required field after removing productId
# Case title (required for DEFAULT_CASE)
string title?;
# Case description (required for DEFAULT_CASE)
string description?;
# Issue type ID (required for DEFAULT_CASE)
int issueTypeKey?;
# Severity key (required for DEFAULT_CASE)
int severityKey?;
# Related case ID (if the case is related to an existing case)
IdString parentCaseId?;
# Conversation ID (if the case is related to a conversation)
IdString conversationId?;
# Catalog ID (required for SERVICE_REQUEST)
IdString catalogId?;
# Catalog Item ID (required for SERVICE_REQUEST)
IdString catalogItemId?;
# Variables for service request (required for SERVICE_REQUEST)
Variable[] variables?;
|};

# Response from creating a case.
Expand Down Expand Up @@ -250,8 +256,8 @@ public type ReferenceTableItem record {|
public type CaseSearchFilters record {|
# List of project IDs to filter
string[] projectIds?;
# List of case type IDs to filter
string[] caseTypeIds?;
# List of case types to filter
CaseType[] caseTypes?;
# Search query for case number, title and description
string searchQuery?;
# List of issue types to filter
Expand Down Expand Up @@ -576,6 +582,8 @@ public type DeployedProduct record {|
string updatedOn;
# Description
string? description;
# Category of the product
ReferenceTableItem? category;
# Associated deployment
ReferenceTableItem? deployment;
# Product information
Expand Down Expand Up @@ -1322,3 +1330,11 @@ public type ConverstaionStateIds record {|
# Abandoned state ID
int abandonded;
|};

# Variable data for service request.
public type Variable record {|
# Variable ID
IdString id;
# Variable value
string value;
|};
41 changes: 41 additions & 0 deletions apps/customer-portal/backend/modules/entity/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,44 @@ public isolated function validateCaseUpdatePayload(CaseUpdatePayload payload) re
}
return;
}

# Validate case create payload based on case type.
#
# + payload - Case create payload
# + return - Validation error message or null if valid
public isolated function validateCaseCreatePayload(CaseCreatePayload payload) returns string? {
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
CaseType caseType = payload.caseType ?: DEFAULT_CASE;
string? title = payload.title;
string? description = payload.description;

if caseType == DEFAULT_CASE {
if title is () {
return "Title is required for default case.";
}
if title.trim().length() == 0 || title.length() > 500 {
return "Title must be between 1 and 500 characters long for default case.";
}
if description is () || description.trim().length() == 0 {
return "Description cannnot be epty for default case.";
}
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
if payload.issueTypeKey is () {
return "Issue type key is required for default case.";
}
if payload.severityKey is () {
return "Severity key is required for default case.";
}
} else if caseType == SERVICE_REQUEST {
if payload.catalogId is () {
return "Catalog ID is required for service request case.";
}
if payload.catalogItemId is () {
return "Catalog Item ID is required for service request case.";
}
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
Variable[]? variables = payload.variables;
if variables is () || variables.length() == 0 {
return "At least one variable is required for service request case.";
}
} else if caseType == ANNOUNCEMENT || caseType == SECURITY_REPORT_ANALYSIS {
return string `Case type ${caseType} is not supported.`;
}
}
10 changes: 7 additions & 3 deletions apps/customer-portal/backend/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public type CaseSearchFilters record {|
int issueId?;
# Status IDs
int[] statusIds?;
# List of case type IDs
string[] caseTypeIds?;
# List of case types
entity:CaseType[] caseTypes?;
# Severity ID
int severityId?;
# Deployment ID
Expand Down Expand Up @@ -419,7 +419,9 @@ public type DeployedProduct record {|
string updatedOn;
# Description
string? description;
# Associated product
# Category
ReferenceItem? category;
# Product
ReferenceItem? product;
# Deployment
ReferenceItem? deployment;
Expand Down Expand Up @@ -1020,4 +1022,6 @@ public type ConversationStats record {|
int openCount?;
# Abandoned chats count
int abandonedCount?;
# Active chats count
int activeCount?;
|};
14 changes: 12 additions & 2 deletions apps/customer-portal/backend/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,10 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
};
}

types:OverallConversationStats { openCount, resolvedCount, abandonedCount} =
types:OverallConversationStats { openCount, resolvedCount, activeCount, abandonedCount} =
getConversationStats(conversationStats);

return { openCount, resolvedCount, abandonedCount };
return { openCount, resolvedCount, activeCount, abandonedCount };
}

# Get project support statistics by ID.
Expand Down Expand Up @@ -830,6 +830,16 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
};
}

string? validateCaseCreatePayload = entity:validateCaseCreatePayload(payload);
if validateCaseCreatePayload is string {
log:printWarn(validateCaseCreatePayload);
return <http:BadRequest>{
body: {
message: validateCaseCreatePayload
}
};
}
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved

entity:CaseCreateResponse|error createdCaseResponse = entity:createCase(userInfo.idToken, payload);
if createdCaseResponse is error {
if getStatusCode(createdCaseResponse) == http:STATUS_UNAUTHORIZED {
Expand Down
6 changes: 4 additions & 2 deletions apps/customer-portal/backend/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public isolated function searchCases(string idToken, string projectId, types:Cas
searchQuery: payload.filters?.searchQuery,
issueTypeKeys: issueId != () ? [issueId] : (),
severityKey: payload.filters?.severityId,
caseTypeIds: payload.filters?.caseTypeIds,
caseTypes: payload.filters?.caseTypes,
stateKeys: payload.filters?.statusIds,
deploymentId: payload.filters?.deploymentId
},
Expand Down Expand Up @@ -245,6 +245,7 @@ public isolated function mapDeployedProducts(entity:DeployedProductsResponse res
let entity:ReferenceTableItem? associatedProduct = product.product
let entity:ReferenceTableItem? deployment = product.deployment
let entity:ReferenceTableItem? version = product.version
let entity:ReferenceTableItem? category = product.category
select {
id: product.id,
createdOn: product.createdOn,
Expand All @@ -257,7 +258,8 @@ public isolated function mapDeployedProducts(entity:DeployedProductsResponse res
updateLevel: product.updateLevel,
product: associatedProduct != () ? {id: associatedProduct.id, label: associatedProduct.name} : (),
deployment: deployment != () ? {id: deployment.id, label: deployment.name} : (),
version: version != () ? {id: version.id, label: version.name} : ()
version: version != () ? {id: version.id, label: version.name} : (),
category: category != () ? {id: category.id, label: category.name} : ()
};
}

Expand Down