From 2366dab173f1968e1e23feb027d9d3cb087137c4 Mon Sep 17 00:00:00 2001 From: Rashmika998 Date: Thu, 5 Mar 2026 12:28:25 +0530 Subject: [PATCH 1/2] Add update change request endpoint --- .../backend/modules/entity/entity.bal | 11 ++++ .../backend/modules/entity/types.bal | 25 ++++++++ apps/customer-portal/backend/service.bal | 57 +++++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/apps/customer-portal/backend/modules/entity/entity.bal b/apps/customer-portal/backend/modules/entity/entity.bal index f4f769c812..4df2153427 100644 --- a/apps/customer-portal/backend/modules/entity/entity.bal +++ b/apps/customer-portal/backend/modules/entity/entity.bal @@ -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 diff --git a/apps/customer-portal/backend/modules/entity/types.bal b/apps/customer-portal/backend/modules/entity/types.bal index 40e5d1b4fa..bcf65cc338 100644 --- a/apps/customer-portal/backend/modules/entity/types.bal +++ b/apps/customer-portal/backend/modules/entity/types.bal @@ -1556,3 +1556,28 @@ public type ProjectChangeRequestStatsResponse record {| ChoiceListItem[] stateCount; json...; |}; + +# Request payload for updating a change request. +public type ChangeRequestUpdatePayload record {| + # Planned start date and time (format: YYYY-MM-DD HH:MM:SS) + DateTime plannedStartOn; +|}; + +# 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...; +|}; diff --git a/apps/customer-portal/backend/service.bal b/apps/customer-portal/backend/service.bal index baf7aa4c8f..8fcd4471a5 100644 --- a/apps/customer-portal/backend/service.bal +++ b/apps/customer-portal/backend/service.bal @@ -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 { + 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 { + 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 { + body: { + message: "Access to update change request information is forbidden for the user!" + } + }; + } + if getStatusCode(response) == http:STATUS_BAD_REQUEST { + return { + body: { + message: "Invalid request parameters for updating change request." + } + }; + } + + string customError = "Failed to update change request."; + log:printError(customError, response); + return { + body: { + message: customError + } + }; + } + return response.changeRequest; + } + # Get change request statistics for a project. # # + id - ID of the project From 06f6b4ba82170c54a2ac8c288b428d6a9f0d4c98 Mon Sep 17 00:00:00 2001 From: Rashmika998 Date: Thu, 5 Mar 2026 13:09:03 +0530 Subject: [PATCH 2/2] Update date field type --- apps/customer-portal/backend/modules/entity/types.bal | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/customer-portal/backend/modules/entity/types.bal b/apps/customer-portal/backend/modules/entity/types.bal index bcf65cc338..0848918952 100644 --- a/apps/customer-portal/backend/modules/entity/types.bal +++ b/apps/customer-portal/backend/modules/entity/types.bal @@ -1557,10 +1557,16 @@ public type ProjectChangeRequestStatsResponse record {| 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) - DateTime plannedStartOn; + DateTimeWithoutTimezone plannedStartOn; |}; # Response from updating a change request.