Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions apps/customer-portal/backend/modules/entity/entity.bal
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,17 @@ public isolated function searchTimeCards(string idToken, TimeCardSearchPayload p
return csEntityClient->/time\-cards/search.post(payload, generateHeaders(idToken));
}

# Search case time cards grouped by case.
#
# + idToken - ID token for authorization
# + payload - Payload containing search criteria for case time cards
# + return - Response containing matching case time cards grouped by case or error
public isolated function searchTimeCardsGroupedByCases(string idToken, TimeCardSearchPayload payload)
returns CaseTimeCardsSearchResponse|error {

return csEntityClient->/cases/time\-cards/search.post(payload, generateHeaders(idToken));
}

# Search conversations of a project.
#
# + idToken - ID token for authorization
Expand Down
45 changes: 45 additions & 0 deletions apps/customer-portal/backend/modules/entity/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,51 @@ public type TimeCardsResponse record {|
*Pagination;
|};

# Billing summary for time cards (billable or non-billable).
public type CaseTimeCardBillingInfo record {|
# Total time
decimal totalTime;
# Count of time cards
int count;
json...;
|};

# Time card summary grouped by case.
public type CaseTimeCardSummary record {|
# Case information
record {|
# System ID of the case
IdString id;
# Case number
string number;
# Case name/summary
string name;
# Last updated date and time
string updatedOn;
# Associated project information
ReferenceTableItem? project;
json...;
|} 'case;
# Total time logged for this case
decimal totalTime;
# Total count of time cards
int totalCount;
# Billable time information
CaseTimeCardBillingInfo billable;
# Non-billable time information
CaseTimeCardBillingInfo nonBillable;
json...;
|};

# Cases time cards search response.
public type CaseTimeCardsSearchResponse record {|
# List of case time card summaries
CaseTimeCardSummary[] cases;
# Total records count
int totalRecords;
*Pagination;
|};

# Conversation data.
public type Conversation record {|
# ID of the chat
Expand Down
37 changes: 35 additions & 2 deletions apps/customer-portal/backend/modules/types/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,6 @@ public type ProductVersion record {|
string? earliestPossibleSupportEolDate;
# Product information
ReferenceItem? product;
json...;
|};

# Product versions response.
Expand Down Expand Up @@ -1123,7 +1122,41 @@ public type TimeCard record {|
# Case number
string number;
|}? case;
json...;
|};

# Time card grouped by case.
public type CaseTimeCard record {|
# Case information
record {|
# ID of the case
entity:IdString id;
# Case number
string number;
# Case name/summary
string name;
# Last updated date and time
string updatedOn;
# Associated project information
ReferenceItem? project;
json...;
|} 'case;
# Total time logged for this case
decimal totalTime;
# Total count of time cards
int totalCount;
# Billable time information
entity:CaseTimeCardBillingInfo billable;
# Non-billable time information
entity:CaseTimeCardBillingInfo nonBillable;
|};

# Cases time cards search response.
public type CaseTimeCardsSearchResponse record {|
# List of case time card summaries
CaseTimeCard[] caseTimeCards;
# Total records count
int totalRecords;
*entity:Pagination;
|};

# Time cards response.
Expand Down
30 changes: 30 additions & 0 deletions apps/customer-portal/backend/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,36 @@ paths:
description: InternalServerError
"403":
description: Forbidden
/projects/{id}/cases/time-cards/search:
post:
operationId: postProjectsIdCasesTimeCardsSearch
parameters:
- name: id
in: path
required: true
schema:
$ref: '#/components/schemas/IdString'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TimeCardSearchPayload'
required: true
responses:
"200":
description: Ok
Comment thread
Rashmika998 marked this conversation as resolved.
Resolved
"400":
description: BadRequest
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorPayload'
"401":
description: Unauthorized
"500":
description: InternalServerError
"403":
description: Forbidden
/projects/{id}/stats/time-cards:
get:
summary: Get time card statistics for a project based on provided date range.
Expand Down
66 changes: 66 additions & 0 deletions apps/customer-portal/backend/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,72 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
};
}

# Search time cards grouped by cases based on provided filters.
#
# + id - ID of the project
# + payload - Time card search payload containing filters and pagination info
# + return - List of time cards grouped by cases matching the criteria or an error
resource function post projects/[entity:IdString id]/cases/time\-cards/search(http:RequestContext ctx,
types:TimeCardSearchPayload payload)
returns http:Ok|http:BadRequest|http:Unauthorized|http:Forbidden|http:InternalServerError {

authorization:UserInfoPayload|error userInfo = ctx.getWithType(authorization:HEADER_USER_INFO);
if userInfo is error {
return <http:InternalServerError>{
body: {
message: ERR_MSG_USER_INFO_HEADER_NOT_FOUND
}
};
}

entity:CaseTimeCardsSearchResponse|error response = entity:searchTimeCardsGroupedByCases(userInfo.idToken,
{
filters: {
projectIds: [id],
startDate: payload.filters?.startDate,
endDate: payload.filters?.endDate,
states: payload.filters?.states
},
pagination: payload.pagination
});
if response is error {
if getStatusCode(response) == http:STATUS_BAD_REQUEST {
return <http:BadRequest>{
body: {
message: "Invalid request parameters for searching time cards grouped by cases."
}
};
}
if getStatusCode(response) == http:STATUS_UNAUTHORIZED {
log:printWarn(string `User: ${userInfo.userId} is not authorized to access time card information!`);
return <http:Unauthorized>{
body: {
message: ERR_MSG_UNAUTHORIZED_ACCESS
}
};
}
if getStatusCode(response) == http:STATUS_FORBIDDEN {
log:printWarn(string `Access to time card information is forbidden for user: ${userInfo.userId}`);
return <http:Forbidden>{
body: {
message: "Access to time card information is forbidden for the user!"
}
};
}

string customError = "Failed to search time cards grouped by cases.";
log:printError(customError, response);
return <http:InternalServerError>{
body: {
message: customError
}
};
}
return <http:Ok>{
body: mapTimeCardSearchResponseGroupedByCases(response)
};
}

# Get time card statistics for a project based on provided date range.
#
# + id - ID of the project
Expand Down
25 changes: 25 additions & 0 deletions apps/customer-portal/backend/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1034,3 +1034,28 @@ public isolated function mapInstanceUsages(entity:InstanceUsageResponse response
endDate: response.endDate
};
}

# Map time cards search response grouped by cases to the desired structure.
#
# + response - Time cards search response grouped by cases from the entity service
# + return - Mapped time cards search response grouped by cases
public isolated function mapTimeCardSearchResponseGroupedByCases(entity:CaseTimeCardsSearchResponse response)
returns types:CaseTimeCardsSearchResponse {

types:CaseTimeCard[] caseTimeCards = from entity:CaseTimeCardSummary caseTimeCard in response.cases
let entity:ReferenceTableItem? project = caseTimeCard.case.project
select {
case: {
id: caseTimeCard.case.id,
number: caseTimeCard.case.number,
name: caseTimeCard.case.name,
updatedOn: caseTimeCard.case.updatedOn,
project: project != () ? {id: project.id, label: project.name} : ()
},
totalTime: caseTimeCard.totalTime,
totalCount: caseTimeCard.totalCount,
billable: caseTimeCard.billable,
nonBillable: caseTimeCard.nonBillable
};
return {caseTimeCards, totalRecords: response.totalRecords, 'limit: response.'limit, offset: response.offset};
}