19626
2023-07-21 e53fdfdd78538a21cddd45b9d3faa1a7e9e37a0a
force-app/main/default/classes/OFSUploadImageRest.cls
@@ -25,19 +25,37 @@
                    res.responseBody = blob.valueOf(jsonResponse);
                    return;
                }
                Attachment att;
                // Attachment att;
                ContentVersion version;
                if (String.isNotBlank(repairQ.contract_consent_id__c)) {
                    att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repairQ.contract_consent_id__c];
                    // att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repairQ.contract_consent_id__c];
                    version = [select Id,VersionData,Title from ContentVersion where Id =: repairQ.contract_consent_id__c];
                } else {
                    att = new Attachment();
                    att.Name = 'ContractConsent.jpg';
                    att.ParentId = rqId;
                    version = new ContentVersion();
                    version.Title = 'ContractConsent.jpg';
                    version.ContentLocation = 's';
                    version.PathOnClient = 'ContractConsent.jpg';
                    // att = new Attachment();
                    // att.Name = 'ContractConsent.jpg';
                    // att.ParentId = rqId;
                }
                att.Body = EncodingUtil.base64Decode(ccImg);
                // att.Body = EncodingUtil.base64Decode(ccImg);
                version.VersionData = EncodingUtil.base64Decode(ccImg);
                try {
                    if (String.isNotBlank(repairQ.contract_consent_id__c)) { update att; }
                    else { insert att; }
                    ccId = att.Id;
                    if (String.isNotBlank(repairQ.contract_consent_id__c)) {
                        update version;
                    }
                    else {
                        insert version;
                        version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
                        ContentDocumentLink link = new ContentDocumentLink();
                        link.LinkedEntityId = rqId;
                        link.ContentDocumentId = version.ContentDocumentId;
                        link.ShareType = 'I';
                        link.Visibility = 'AllUsers';
                        insert link;
                    }
                    ccId = version.Id;
                    repairQ.contract_consent_id__c = ccId;
                } catch ( Exception ex ) {
                    //TODO:
@@ -60,19 +78,37 @@
                }
            }
            if (String.isNotBlank(acImg)) {
                Attachment att;
                // Attachment att;
                ContentVersion version;
                if (String.isNotBlank(repair.acceptance_id__c)) {
                    att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repair.acceptance_id__c];
                    // att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repair.acceptance_id__c];
                    version = [select Id,Title,VersionData from ContentVersion where Id =: repair.acceptance_id__c];
                } else {
                    att = new Attachment();
                    att.Name = 'Acceptance.jpg';
                    att.ParentId = repairId;
                    version = new ContentVersion();
                    version.Title = 'Acceptance.jpg';
                    version.ContentLocation = 's';
                    version.PathOnClient = 'Acceptance.jpg';
                    // att = new Attachment();
                    // att.Name = 'Acceptance.jpg';
                    // att.ParentId = repairId;
                }
                att.Body = EncodingUtil.base64Decode(acImg);
                // att.Body = EncodingUtil.base64Decode(acImg);
                version.VersionData = EncodingUtil.base64Decode(acImg);
                try {
                    if (String.isNotBlank(repair.acceptance_id__c)) { update att; }
                    else { insert att; }
                    acId = att.Id;
                    if (String.isNotBlank(repair.acceptance_id__c)) {
                        update version;
                    }
                    else {
                        insert version;
                        version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
                        ContentDocumentLink link = new ContentDocumentLink();
                        link.ShareType = 'I';
                        link.Visibility = 'AllUsers';
                        link.ContentDocumentId = version.ContentDocumentId;
                        link.LinkedEntityId = repairId;
                        insert link;
                    }
                    acId = version.Id;
                } catch ( Exception ex ) {
                    //TODO:
                    //error message:cannot update exception