Skip to content

Commit

Permalink
♻️ api: some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Steph0 committed Oct 8, 2024
1 parent ec36e85 commit 199ffb6
Showing 1 changed file with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ export async function verifyCandidateSubscriptions({
certificationBadgesService,
}) {
const session = await sessionRepository.get({ id: sessionId });
const { userId } = candidate;

if (candidate.hasCoreSubscription()) {
const placementProfile = await placementProfileService.getPlacementProfile({
userId,
userId: candidate.userId,
limitDate: candidate.reconciledAt,
});

Expand All @@ -49,23 +48,15 @@ export async function verifyCandidateSubscriptions({
}

if (_doesNeedEligibilityCheck(session, candidate)) {
const userPixCertifications = await pixCertificationRepository.findByUserId({ userId });
const userPixCertifications = await pixCertificationRepository.findByUserId({ userId: candidate.userId });

if (!_hasValidCoreCertification(userPixCertifications)) {
throw new CertificationCandidateEligibilityError();
}

const highestUserValidPixScore = _getHighestUserValidPixScore(userPixCertifications);

// TODO: petit refacto mettre ensemble userAcquiredBadges et subscribedHighestBadgeAcquisition
const userAcquiredBadgeAcquisitions = await certificationBadgesService.findLatestBadgeAcquisitions({
userId,
limitDate: candidate.reconciledAt,
});

const subscribedHighestBadgeAcquisition = _getSubscribedHighestBadgeAcquisition({
userAcquiredBadgeAcquisitions,
const subscribedHighestBadgeAcquisition = await _findHighestBadgeAcquisitionForCandidateSubscription({
candidate,
certificationBadgesService,
});

if (_isSubscribedUserBadgeOutDated(subscribedHighestBadgeAcquisition)) {
Expand All @@ -86,6 +77,7 @@ export async function verifyCandidateSubscriptions({
subscribedHighestBadgeAcquisition,
);

const highestUserValidPixScore = _getHighestUserValidPixScore(userPixCertifications);
if (
!_isUserPixScoreSufficientForBadge({
subscribedComplementaryCertificationBadge,
Expand All @@ -97,6 +89,25 @@ export async function verifyCandidateSubscriptions({
}
}
}

/**
* @param {Object} params
* @param {CertificationBadgesService} params.certificationBadgesService
* @param {Candidate} params.candidate
* @returns {CertifiableBadgeAcquisition} highest badge acquired that the candidate has been subscribed to
*/
async function _findHighestBadgeAcquisitionForCandidateSubscription({ candidate, certificationBadgesService }) {
const userAcquiredBadgeAcquisitions = await certificationBadgesService.findLatestBadgeAcquisitions({
userId: candidate.userId,
limitDate: candidate.reconciledAt,
});

return _getSubscribedHighestBadgeAcquisition({
userAcquiredBadgeAcquisitions,
candidate,
});
}

/**
* @param {CertifiableBadgeAcquisition} subscribedBadgeAcquisition
* @returns {boolean} true if badge exists and is tagged outdated
Expand Down

0 comments on commit 199ffb6

Please sign in to comment.