diff --git a/IMPLEMENTATION_PLAN.md b/IMPLEMENTATION_PLAN.md index 8f72fb6..f8fe9b8 100644 --- a/IMPLEMENTATION_PLAN.md +++ b/IMPLEMENTATION_PLAN.md @@ -14,7 +14,7 @@ - [x] **Task 3 — Tests for createEnvelope():** Add test coverage in `DocusignESignatureServiceTest` — success path (mock 201), failure path (mock 400), blank email guard. (NFR-001, TC-001, TC-002) -- [ ] **Task 4 — persistEnvelopeResult() + CaseContext extension:** Add `persistEnvelopeResult()` to `CLMAdminService`. Extend `CaseContext` inner class and `getCaseContext()` SOQL to include the 5 eSignature fields. (FR-003, FR-004) +- [x] **Task 4 — persistEnvelopeResult() + CaseContext extension:** Add `persistEnvelopeResult()` to `CLMAdminService`. Extend `CaseContext` inner class and `getCaseContext()` SOQL to include the 5 eSignature fields. (FR-003, FR-004) - [ ] **Task 5 — Tests for persistEnvelopeResult():** Add test coverage in `CLMAdminServiceTest` — verify fields written correctly, `ESignature_Sent_At__c` is set, `ESignature_Completed_At__c` is NOT written on a "sent" result. (NFR-001, TC-003) diff --git a/force-app/main/default/classes/CLMAdminService.cls b/force-app/main/default/classes/CLMAdminService.cls index 0dca693..bffbbf1 100644 --- a/force-app/main/default/classes/CLMAdminService.cls +++ b/force-app/main/default/classes/CLMAdminService.cls @@ -22,6 +22,11 @@ public with sharing class CLMAdminService { @AuraEnabled public String attachedFileUrl; @AuraEnabled public Datetime lastDocGenRequestedAt; @AuraEnabled public Datetime lastDocGenCompletedAt; + @AuraEnabled public String eSignatureEnvelopeId; + @AuraEnabled public String eSignatureEnvelopeStatus; + @AuraEnabled public String eSignatureEnvelopeUrl; + @AuraEnabled public Datetime eSignatureSentAt; + @AuraEnabled public Datetime eSignatureCompletedAt; @AuraEnabled public List deficiencies; } @@ -313,6 +318,11 @@ public with sharing class CLMAdminService { Attached_File_Url__c, Last_DocGen_Requested_At__c, Last_DocGen_Completed_At__c, + ESignature_Envelope_Id__c, + ESignature_Envelope_Status__c, + ESignature_Sent_At__c, + ESignature_Completed_At__c, + ESignature_Envelope_Url__c, (SELECT Id, Deficiency_Number__c, Description__c, @@ -344,6 +354,11 @@ public with sharing class CLMAdminService { context.attachedFileUrl = appraiserCase.Attached_File_Url__c; context.lastDocGenRequestedAt = appraiserCase.Last_DocGen_Requested_At__c; context.lastDocGenCompletedAt = appraiserCase.Last_DocGen_Completed_At__c; + context.eSignatureEnvelopeId = appraiserCase.ESignature_Envelope_Id__c; + context.eSignatureEnvelopeStatus = appraiserCase.ESignature_Envelope_Status__c; + context.eSignatureEnvelopeUrl = appraiserCase.ESignature_Envelope_Url__c; + context.eSignatureSentAt = appraiserCase.ESignature_Sent_At__c; + context.eSignatureCompletedAt = appraiserCase.ESignature_Completed_At__c; context.deficiencies = new List(); if (appraiserCase.Deficiencies__r != null) { @@ -433,6 +448,29 @@ public with sharing class CLMAdminService { return result; } + @AuraEnabled(cacheable=false) + public static void persistEnvelopeResult( + Id caseId, + String envelopeId, + String envelopeStatus, + String envelopeUri + ) { + if (caseId == null) { + return; + } + + Appraiser_Case__c updateCase = new Appraiser_Case__c(Id = caseId); + updateCase.ESignature_Envelope_Id__c = envelopeId; + updateCase.ESignature_Envelope_Status__c = envelopeStatus; + updateCase.ESignature_Sent_At__c = System.now(); + + if (String.isNotBlank(envelopeUri)) { + updateCase.ESignature_Envelope_Url__c = envelopeUri; + } + + update updateCase; + } + private static String formatAddress(Appraiser_Case__c appraiserCase) { return AppraiserCasePayloadBuilder.formatMailingAddress( appraiserCase.Property_Street__c,