Skip to content

Commit

Permalink
Change qualification creation from queued to immediate
Browse files Browse the repository at this point in the history
  • Loading branch information
martyn-w committed Sep 5, 2024
1 parent 2a87749 commit 9b68690
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions GetIntoTeachingApi/Services/CandidateUpserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<TeachingEventRegistration> ClearTeachingEventRegistrations(Candidate candidate)
Expand Down Expand Up @@ -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<CandidateQualification> 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<TeachingEventRegistration> registrations, Candidate candidate)
{
Expand All @@ -165,21 +182,7 @@ private void SaveTeachingEventRegistrations(IEnumerable<TeachingEventRegistratio
_jobClient.Enqueue<UpsertModelWithCandidateIdJob<TeachingEventRegistration>>((x) => x.Run(json, null));
}
}

private void SaveQualifications(IEnumerable<CandidateQualification> 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<UpsertModelWithCandidateIdJob<CandidateQualification>>((x) => x.Run(json, null));
}
}
}


private void SaveApplicationForms(IEnumerable<ApplicationForm> applicationForms, Candidate candidate)
{
Expand Down

0 comments on commit 9b68690

Please sign in to comment.