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 @@ -431,6 +431,17 @@ public isolated function searchChangeRequests(string idToken, ChangeRequestSearc
return csEntityClient->/change\-requests/search.post(payload, generateHeaders(idToken));
}

# Update a change request.
#
# + idToken - ID token for authorization
# + changeRequestId - Unique ID of the change request to be updated
# + payload - Change request update payload containing details to be updated in the change request
# + return - Change request update response containing details of the updated change request or error
public isolated function updateChangeRequest(string idToken, string changeRequestId, ChangeRequestUpdatePayload payload)
returns ChangeRequestUpdateResponse|error {

return csEntityClient->/change\-requests/[changeRequestId].patch(payload, generateHeaders(idToken));
}
# Search catalogs.
#
# + idToken - ID token for authorization
Expand Down
31 changes: 31 additions & 0 deletions apps/customer-portal/backend/modules/entity/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1556,3 +1556,34 @@ public type ProjectChangeRequestStatsResponse record {|
ChoiceListItem[] stateCount;
json...;
|};

# DateTime string type with YYYY-MM-DD HH:MM:SS format constraint.
@constraint:String {
pattern: re `^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) ([01]\d|2[0-3]):[0-5]\d:[0-5]\d$`
}
public type DateTimeWithoutTimezone string;

# Request payload for updating a change request.
public type ChangeRequestUpdatePayload record {|
# Planned start date and time (format: YYYY-MM-DD HH:MM:SS)
DateTimeWithoutTimezone plannedStartOn;
|};
Comment thread
Rashmika998 marked this conversation as resolved.

# Response from updating a change request.
public type ChangeRequestUpdateResponse record {|
# Success message
string message;
# Updated change request details
UpdatedChangeRequest changeRequest;
|};

# Updated change request details.
public type UpdatedChangeRequest record {|
# ID of the updated change request
IdString id;
# Updated date and time
string updatedOn;
# User who updated the change request
string updatedBy;
json...;
|};
57 changes: 57 additions & 0 deletions apps/customer-portal/backend/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,63 @@ service http:InterceptableService / on new http:Listener(9090, listenerConf) {
return mapChangeRequestResponse(response);
}

# Update a change request by change request ID.
#
# + id - ID of the change request
# + payload - Change request update payload containing fields to be updated
# + return - Updated change request details or an error
resource function patch change\-requests/[entity:IdString id](http:RequestContext ctx,
entity:ChangeRequestUpdatePayload payload) returns entity:UpdatedChangeRequest|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:ChangeRequestUpdateResponse|error response = entity:updateChangeRequest(userInfo.idToken, id, payload);
if response is error {
if getStatusCode(response) == http:STATUS_UNAUTHORIZED {
log:printWarn(string `User: ${
userInfo.userId} is not authorized to update change request information!`);
return <http:Unauthorized>{
body: {
message: ERR_MSG_UNAUTHORIZED_ACCESS
}
};
}
if getStatusCode(response) == http:STATUS_FORBIDDEN {
log:printWarn(string `Access to update change request information is forbidden for user: ${
userInfo.userId}`);
return <http:Forbidden>{
body: {
message: "Access to update change request information is forbidden for the user!"
}
};
}
if getStatusCode(response) == http:STATUS_BAD_REQUEST {
return <http:BadRequest>{
body: {
message: "Invalid request parameters for updating change request."
}
};
}

string customError = "Failed to update change request.";
log:printError(customError, response);
return <http:InternalServerError>{
body: {
message: customError
}
};
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return response.changeRequest;
}

# Get change request statistics for a project.
#
# + id - ID of the project
Expand Down