diff --git a/src/Controllers/Storage/ProcessController.cs b/src/Controllers/Storage/ProcessController.cs index ff540b7..52d1b66 100644 --- a/src/Controllers/Storage/ProcessController.cs +++ b/src/Controllers/Storage/ProcessController.cs @@ -61,50 +61,45 @@ public ProcessController( [ProducesResponseType(StatusCodes.Status404NotFound)] [Produces("application/json")] public async Task> PutProcess( - int instanceOwnerPartyId, - Guid instanceGuid, - [FromBody] ProcessState processState) + int instanceOwnerPartyId, + Guid instanceGuid, + [FromBody] ProcessState processState + ) { - Instance existingInstance; + Instance existingInstance = await _instanceRepository.GetOne( + instanceOwnerPartyId, + instanceGuid + ); - existingInstance = await _instanceRepository.GetOne(instanceOwnerPartyId, instanceGuid); - - if (existingInstance == null) + if (existingInstance is null) { return NotFound(); } - string altinnTaskType = existingInstance.Process?.CurrentTask?.AltinnTaskType; string taskId = null; - - var moveNextFlows = new []{"CompleteCurrentMoveToNext", "AbandonCurrentMoveToNext"}; - if (processState?.CurrentTask?.FlowType is not null && !moveNextFlows.Contains(processState.CurrentTask.FlowType)) + string altinnTaskType = existingInstance.Process?.CurrentTask?.AltinnTaskType; + + if (processState?.CurrentTask?.FlowType == "AbandonCurrentMoveToNext") + { + altinnTaskType = "reject"; + } + else if ( + processState?.CurrentTask?.FlowType is not null + && processState.CurrentTask.FlowType != "CompleteCurrentMoveToNext" + ) { altinnTaskType = processState.CurrentTask.AltinnTaskType; taskId = processState.CurrentTask.ElementId; } - string action; - - switch (altinnTaskType) + string action = altinnTaskType switch { - case "data": - case "feedback": - action = "write"; - break; - case "payment": - action = "pay"; - break; - case "confirmation": - action = "confirm"; - break; - case "signing": - action = "sign"; - break; - default: - action = altinnTaskType; - break; - } + "data" or "feedback" => "write", + "payment" => "pay", + "confirmation" => "confirm", + "signing" => "sign", + _ => altinnTaskType, + }; bool authorized = await _authorizationService.AuthorizeInstanceAction(existingInstance, action, taskId); @@ -114,7 +109,7 @@ public async Task> PutProcess( } // Archiving instance if process was ended - if (existingInstance.Process.Ended == null && processState?.Ended != null) + if (existingInstance.Process?.Ended is null && processState?.Ended is not null) { existingInstance.Status ??= new InstanceStatus(); existingInstance.Status.IsArchived = true;