public async Task SubmitDocumentForVerification()

in packages/ekyc-api/src/ekyc-api/Controllers/SessionController.cs [243:310]


        public async Task SubmitDocumentForVerification(string sessionId, string s3Key, string expectedDocumentType)
        {
            if (string.IsNullOrEmpty(sessionId))
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "Session ID cannot be blank.");

            if (string.IsNullOrEmpty(s3Key))
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "S3 key cannot be blank.");

            if (string.IsNullOrEmpty(expectedDocumentType))
                throw new HttpStatusException(HttpStatusCode.InternalServerError,
                    "Expected document type cannot be blank.");

            // Check that the document type is supported
            DocumentTypes docType;

            if (!Enum.TryParse(expectedDocumentType, true, out docType))
                throw new HttpStatusException(HttpStatusCode.InternalServerError,
                    $"Document type {expectedDocumentType} is not supported.");

            // Check if the session exists
            var sessionValid = await _sessionManager.SessionExistsAndIsValid(sessionId);

            if (!sessionValid)
                throw new HttpStatusException(HttpStatusCode.InternalServerError,
                    $"Session ID {sessionId} not found or has expired.");

            s3Key = sessionId + "/" + s3Key;


            var config = new DynamoDBOperationConfig
            {
                OverrideTableName = Globals.SessionTableName
            };

            var item = await _dbContext.LoadAsync<SessionObject>(sessionId, config);

            if (item == null) throw new HttpStatusException(HttpStatusCode.InternalServerError, "Session not found.");

            var imaging = new Imaging(_amazonS3, _documentChecker);

            Image img;

            // Validate the document type

            try
            {
                img = await imaging.GetImageFromStorage(s3Key);
            }
            catch (ImageFormatException)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "Key provided is not a valid image.");
            }
            catch (Exception ex)
            {
                throw new HttpStatusException(HttpStatusCode.InternalServerError, ex.Message);
            }

            if (img == null)
                throw new HttpStatusException(HttpStatusCode.InternalServerError, "Image is not valid.");

            await _livenessChecker.VerifyImageSize(img);

            item.documentImageKey = s3Key;

            item.documentType = docType.ToString();

            await _dbContext.SaveAsync(item, config);
        }