Skip to content

Commit

Permalink
Merge pull request #2094 from navikt/TOLK-2233
Browse files Browse the repository at this point in the history
Tolk 2233 : Bestillinger kommer inn uten dato og tidspunkt
  • Loading branch information
olsenrasmus authored Oct 15, 2024
2 parents d0bd50e + 38fbaf1 commit bc6f71f
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
35 changes: 35 additions & 0 deletions force-app/main/triggers/classes/HOT_RequestHandler.cls
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
public without sharing class HOT_RequestHandler extends MyTriggers {
private static void handleException(Exception e) {
LoggerUtility logger = new LoggerUtility();
logger.exception(e, CRM_ApplicationDomain.Domain.HOT);
logger.publishSynch();
}
public override void onBeforeInsert() {
setStatusDefault((List<HOT_Request__c>) records);
setOrdererField((List<HOT_Request__c>) records);
Expand Down Expand Up @@ -599,4 +604,34 @@ public without sharing class HOT_RequestHandler extends MyTriggers {
}
}
}
@AuraEnabled
public static boolean isErrorOnRequestCreate(String requestId) {
Boolean isError = false;
HOT_Request__c createdRequest = [
SELECT Id, StartTime__c, EndTime__c, NumberOfWorkOrders__c
FROM HOT_Request__c
WHERE Id = :requestId
];
if (createdRequest.StartTime__c == null || createdRequest.EndTime__c == null) {
isError = true;
} else {
List<WorkOrder> createdWorkOrders = [SELECT Id FROM WorkOrder WHERE HOT_Request__c = :requestId];
if (createdRequest.NumberOfWorkOrders__c != createdWorkOrders.size()) {
isError = true;
try {
delete createdWorkOrders;
} catch (Exception e) {
handleException(e);
}
}
}
if (isError) {
try {
delete createdRequest;
} catch (Exception e) {
handleException(e);
}
}
return isError;
}
}
26 changes: 26 additions & 0 deletions force-app/main/triggers/classes/HOT_RequestHandlerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -823,4 +823,30 @@ private class HOT_RequestHandlerTest {
System.AssertEquals('Oslo', workorderResult.HOT_InterpretationPostalCity__c, 'City did not get updated');
System.AssertEquals('0166', workorderResult.HOT_InterpretationPostalCode__c, 'Postalcode did not get updated');
}
@IsTest
public static void checkIfRequestCreatedCorrectlyTrueTest() {
Test.startTest();
WorkType workType = HOT_TestDataFactory.createWorkType();
insert workType;
HOT_Request__c request = HOT_TestDataFactory.createRequest('TEST', workType);
insert request;
WorkOrder workOrder = HOT_TestDataFactory.createWorkOrder(request, workType);
insert workOrder;

Boolean result = HOT_RequestHandler.isErrorOnRequestCreate(request.Id);
//Den sjekker om det ble feil ved opprettelse. False betyr at det ikke er noe feil
System.AssertEquals(false, result, 'Should have been shown to be created correctly');
}
@IsTest
public static void checkIfRequestCreatedCorrectlyFalseTest() {
Test.startTest();
WorkType workType = HOT_TestDataFactory.createWorkType();
insert workType;
HOT_Request__c request = HOT_TestDataFactory.createRequest('TEST', workType);
insert request;

Boolean result = HOT_RequestHandler.isErrorOnRequestCreate(request.Id);
//Den sjekker om det ble feil ved opprettelse. True betyr at det er feil
System.AssertEquals(true, result, 'Should have been shown to be not created correctly');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,27 @@ <h2 class="typo-undertittel">Legg ved filer til denne bestillingen</h2>
<br />
</div>
</div>
<div class="main-content hidden submitted-error">
<div class="main-content dialog-boks skjema-max-width">
<lightning-icon
icon-name="utility:warning"
alternative-text="Advarsel"
title="Advarsel"
variant="warning"
size="large"
>
</lightning-icon>
<br />
<h2
class="typo-undertittel h2-errorMessage"
id="errorMessage"
tabindex="-1"
role="alert"
aria-live="polite"
>
Noe gikk galt under innsending av din bestilling. Vennligst prøv igjen, eller kontakt tolketjenesten om
problemet vedvarer.
</h2>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LightningElement, wire, track } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import createAndUpdateWorkOrders from '@salesforce/apex/HOT_RequestHandler.createAndUpdateWorkOrders';
import isErrorOnRequestCreate from '@salesforce/apex/HOT_RequestHandler.isErrorOnRequestCreate';
import getRequestStatus from '@salesforce/apex/HOT_RequestListController.getRequestStatus';
import createWorkOrders from '@salesforce/apex/HOT_CreateWorkOrderService.createWorkOrdersFromCommunity';
import checkDuplicates from '@salesforce/apex/HOT_DuplicateHandler.checkDuplicates';
Expand Down Expand Up @@ -177,8 +178,12 @@ export default class Hot_requestFormWrapper extends NavigationMixin(LightningEle
this.template.querySelector('c-alertdialog').showModal();
this.spin = false;
}
@track requestId;

handleSuccess(event) {
const record = event.detail.id;
this.requestId = record;

if (this.editNotAllowed) {
return;
}
Expand All @@ -202,6 +207,13 @@ export default class Hot_requestFormWrapper extends NavigationMixin(LightningEle
window.scrollTo(0, 0);
}

hideFormAndShowError() {
this.template.querySelector('.submitted-loading').classList.add('hidden');
this.template.querySelector('.submitted-false').classList.add('hidden');
this.template.querySelector('.submitted-error').classList.remove('hidden');
this.template.querySelector('.h2-errorMessage').focus();
}

editNotAllowed = false;
showModalOnEditNotAllowed() {
this.editNotAllowed = true;
Expand Down Expand Up @@ -230,19 +242,39 @@ export default class Hot_requestFormWrapper extends NavigationMixin(LightningEle
recurringEndDate: new Date(timeInput.repeatingEndDate).getTime()
}).then(() => {
this.spin = false;
this.hideFormAndShowSuccess();
if (this.isCreatedCorrectly(this.requestId)) {
this.hideFormAndShowSuccess();
} else {
this.hideFormAndShowError();
}
});
} catch (error) {
console.log(JSON.stringify(error));
this.hideFormAndShowError();
}
} else {
createAndUpdateWorkOrders({ requestId: this.recordId, times: timeInput.times }).then(() => {
this.spin = false;
this.hideFormAndShowSuccess();
if (this.isCreatedCorrectly(this.requestId)) {
this.hideFormAndShowSuccess();
} else {
this.hideFormAndShowError();
}
});
}
}
}
isCreatedCorrectly(recordId) {
return isErrorOnRequestCreate({
requestId: recordId
}).then((result) => {
if (result === false) {
return true;
} else {
return false;
}
});
}

@track previousPage = 'home';
connectedCallback() {
Expand Down

0 comments on commit bc6f71f

Please sign in to comment.