From 9b686901cdab78080e7963eddea17d7bf48c18aa Mon Sep 17 00:00:00 2001 From: Martyn Whitwell Date: Thu, 5 Sep 2024 14:36:46 +0100 Subject: [PATCH] Change qualification creation from queued to immediate --- .../Services/CandidateUpserter.cs | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/GetIntoTeachingApi/Services/CandidateUpserter.cs b/GetIntoTeachingApi/Services/CandidateUpserter.cs index 8aacebfec..dafb0801f 100644 --- a/GetIntoTeachingApi/Services/CandidateUpserter.cs +++ b/GetIntoTeachingApi/Services/CandidateUpserter.cs @@ -33,8 +33,8 @@ public void Upsert(Candidate candidate) UpdateEventSubscriptionType(candidate); SaveCandidate(candidate); - SaveQualifications(qualifications, candidate); + SavePastTeachingPositions(pastTeachingPositions, candidate); SaveApplicationForms(applicationForms, candidate); SaveTeachingEventRegistrations(registrations, candidate); @@ -43,6 +43,9 @@ public void Upsert(Candidate candidate) SaveSchoolExperiences(schoolExperiences, candidate); IncrementCallbackBookingQuotaNumberOfBookings(phoneCall); + + // Re-add qualifications back to candidate object to ensure it is correctly returned + AddQualifications(qualifications, candidate); } private static IEnumerable ClearTeachingEventRegistrations(Candidate candidate) @@ -145,9 +148,23 @@ private void UpdateEventSubscriptionType(Candidate candidate) private void SaveCandidate(Candidate candidate) { candidate.IsNewRegistrant = candidate.Id == null; - _crm.Save(candidate); } + + private void SaveQualifications(IEnumerable qualifications, Candidate candidate) + { + foreach (var qualification in qualifications) + { + // only add the degree qualification to the CRM if it doesn't already exist + if (!_crm.CandidateHasDegreeQualification((Guid)candidate.Id, CandidateQualification.DegreeType.Degree, + qualification.DegreeSubject)) + { + qualification.CandidateId = (Guid)candidate.Id; + // call the CRM immediate so we get qualification ID and prevent duplicate records from being created + _crm.Save(qualification); + } + } + } private void SaveTeachingEventRegistrations(IEnumerable registrations, Candidate candidate) { @@ -165,21 +182,7 @@ private void SaveTeachingEventRegistrations(IEnumerable>((x) => x.Run(json, null)); } } - - private void SaveQualifications(IEnumerable qualifications, Candidate candidate) - { - foreach (var qualification in qualifications) - { - if (!_crm.CandidateHasDegreeQualification((Guid)candidate.Id, CandidateQualification.DegreeType.Degree, - qualification.DegreeSubject)) - { - qualification.CandidateId = (Guid)candidate.Id; - string json = qualification.SerializeChangeTracked(); - - _jobClient.Enqueue>((x) => x.Run(json, null)); - } - } - } + private void SaveApplicationForms(IEnumerable applicationForms, Candidate candidate) {