Skip to content

Commit e06796c

Browse files
authoredSep 5, 2024··
Merge pull request #350 from navikt/TOLK-2358
TOLK-2358 Ikke lenger mulig å melde på flere på samme e-postadresse
2 parents d84fae6 + 22ce5b1 commit e06796c

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed
 

‎force-app/main/default/classes/CourseRegistrationController.cls

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
public with sharing class CourseRegistrationController {
1+
public without sharing class CourseRegistrationController {
22
@AuraEnabled
33
public static String createRegistration(String fields, String courseId) {
44
try {
5-
/* Boolean duplicate = checkForDuplicates( contactId, courseId );
6-
if ( duplicate ) { return 'Du er allerede påmeldt dette kurset'; }
7-
insertRegistration( contactId, courseId );*/
5+
Boolean duplicate = checkForDuplicates(fields, courseId );
6+
if ( duplicate ) {
7+
return 'Du er allerede påmeldt dette kurset, vennligst bruk en annen e-postadresse.';
8+
}
89
Boolean courseIsFull = checkIfCourseIsFull(courseId);
9-
1010
if (fields != null) {
1111
insertRegistration(fields, courseId);
1212
}
1313
if (courseIsFull) {
1414
return 'Registrering vellykket! Du er nå satt på venteliste og vil motta bekreftelse på e-post dersom du blir tildelt en plass.';
1515
}
16-
1716
return 'Påmelding vellykket. Du vil om kort tid motta en bekreftelse på e-post';
1817
} catch (Exception e) {
1918
return 'Det oppsto en feil. Prøv igjen senere.';
2019
}
2120
}
21+
2222
@AuraEnabled
2323
public static Course__c getCourseFields(String courseId) {
2424
return [
@@ -86,17 +86,15 @@ public with sharing class CourseRegistrationController {
8686
insert registration;
8787
}
8888
}
89-
90-
/*
91-
public static Boolean checkForDuplicates( Id contactId, Id courseId ) {
89+
90+
public static Boolean checkForDuplicates( String fields, Id courseId ) {
91+
CourseRegistrationModel model = CourseRegistrationModel.parse(fields);
9292
List<CourseRegistration__c> existingRecord =
93-
[SELECT Id, Course__c, CourseParticipant__c
93+
[SELECT Id, Course__c, CourseParticipant__r.Email
9494
FROM CourseRegistration__c
9595
WHERE Course__c =: courseId
96-
AND CourseParticipant__c =: contactId LIMIT 1];
97-
98-
Boolean exists = existingRecord.size() > 0 ? true : false;
96+
AND CourseParticipant__r.Email =: model.email LIMIT 1];
9997

100-
return exists;
101-
}*/
98+
return existingRecord.size() > 0;
99+
}
102100
}

‎force-app/main/default/classes/CourseRegistrationControllerTest.cls

+13-3
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,28 @@ private with sharing class CourseRegistrationControllerTest {
2525
wrapper.email = 'test@test.com';
2626
wrapper.companyNumber = '677777';
2727
wrapper.source = 'Kurs';
28-
2928
String fields = JSON.serialize(wrapper);
3029

30+
CourseRegistrationModel wrapperDuplicate = new CourseRegistrationModel();
31+
wrapperDuplicate.firstName = 'test2';
32+
wrapperDuplicate.lastName = 'etternavn2';
33+
wrapperDuplicate.phone = '90080902';
34+
wrapperDuplicate.email = 'test@test.com';
35+
wrapperDuplicate.companyNumber = '677777';
36+
wrapperDuplicate.source = 'Kurs';
37+
String fieldsOnDuplicate = JSON.serialize(wrapperDuplicate);
38+
3139
Test.StartTest();
32-
String result = CourseRegistrationController.createRegistration(fields, courseId);
40+
String resultOfInitialReg = CourseRegistrationController.createRegistration(fields, courseId);
3341
String result2 = CourseRegistrationController.createRegistration(fields, noCourseId);
42+
String resultOfDuplicateReg = CourseRegistrationController.createRegistration(fieldsOnDuplicate, courseId);
3443
Test.StopTest();
3544
System.assertEquals(
3645
'Påmelding vellykket. Du vil om kort tid motta en bekreftelse på e-post',
37-
result,
46+
resultOfInitialReg,
3847
'Registration successfull'
3948
);
4049
System.assertEquals('Det oppsto en feil. Prøv igjen senere.', result2, 'Course id missing');
50+
System.assertEquals('Du er allerede påmeldt dette kurset, vennligst bruk en annen e-postadresse.', resultOfDuplicateReg, 'Duplicate registration');
4151
}
4252
}

0 commit comments

Comments
 (0)
Please sign in to comment.