-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle checks for not outdated badge acquisitions
- Loading branch information
1 parent
20152eb
commit 608f02a
Showing
5 changed files
with
207 additions
and
7 deletions.
There are no files selected for viewing
51 changes: 47 additions & 4 deletions
51
api/src/certification/enrolment/domain/usecases/get-user-certification-eligibility.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,55 @@ | ||
import { UserCertificationEligibility } from '../read-models/UserCertificationEligibility.js'; | ||
import { CertificationEligibility, UserCertificationEligibility } from '../read-models/UserCertificationEligibility.js'; | ||
|
||
const getUserCertificationEligibility = async function ({ userId, limitDate, placementProfileService }) { | ||
const getUserCertificationEligibility = async function ({ | ||
userId, | ||
limitDate, | ||
placementProfileService, | ||
certificationBadgesService, | ||
complementaryCertificationCourseRepository, | ||
}) { | ||
const placementProfile = await placementProfileService.getPlacementProfile({ userId, limitDate }); | ||
const isCertifiable = placementProfile.isCertifiable(); | ||
|
||
const userAcquiredBadges = await certificationBadgesService.findLatestBadgeAcquisitions({ | ||
userId, | ||
limitDate, | ||
}); | ||
const certificationEligibilities = []; | ||
const complementaryCertificationAcquiredByUser = await complementaryCertificationCourseRepository.findByUserId({ | ||
userId, | ||
}); | ||
for (const acquiredBadge of userAcquiredBadges) { | ||
if (!acquiredBadge.isOutdated) { | ||
const isAcquiredExpectedLevel = _hasAcquiredComplementaryCertificationForExpectedLevel( | ||
complementaryCertificationAcquiredByUser, | ||
acquiredBadge, | ||
); | ||
certificationEligibilities.push( | ||
new CertificationEligibility({ | ||
label: acquiredBadge.complementaryCertificationBadgeLabel, | ||
imageUrl: acquiredBadge.complementaryCertificationBadgeImageUrl, | ||
isOutdated: acquiredBadge.isOutdated, | ||
isAcquiredExpectedLevel, | ||
}), | ||
); | ||
} | ||
} | ||
return new UserCertificationEligibility({ | ||
id: userId, | ||
isCertifiable: placementProfile.isCertifiable(), | ||
certificationEligibilities: [], | ||
isCertifiable, | ||
certificationEligibilities, | ||
}); | ||
}; | ||
|
||
function _hasAcquiredComplementaryCertificationForExpectedLevel( | ||
complementaryCertificationAcquiredByUser, | ||
acquiredBadge, | ||
) { | ||
return complementaryCertificationAcquiredByUser.some( | ||
(certificationTakenByUser) => | ||
certificationTakenByUser.isAcquiredExpectedLevelByPixSource() && | ||
acquiredBadge.complementaryCertificationBadgeId === certificationTakenByUser.complementaryCertificationBadgeId, | ||
); | ||
} | ||
|
||
export { getUserCertificationEligibility }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters