Skip to content

Commit

Permalink
♻️ api: refactor usecase for more readability
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy committed Oct 24, 2024
1 parent baefa63 commit c6068b6
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,6 @@ const retrieveLastOrCreateCertificationCourse = async function ({
};
}

let lang;
if (SessionVersion.isV3(session.version)) {
const user = await userRepository.get(userId);
const isUserLanguageValid = _validateUserLanguage(languageService, user.lang);

if (!isUserLanguageValid) {
throw new LanguageNotSupportedError(user.lang);
}

lang = user.lang;
}

return _startNewCertification({
session,
userId,
Expand All @@ -113,11 +101,12 @@ const retrieveLastOrCreateCertificationCourse = async function ({
assessmentRepository,
certificationCourseRepository,
certificationCenterRepository,
userRepository,
languageService,
certificationChallengesService,
placementProfileService,
verifyCertificateCodeService,
certificationBadgesService,
lang,
});
};

Expand Down Expand Up @@ -187,7 +176,9 @@ async function _blockCandidateFromRestartingWithoutExplicitValidation(
* @param {CertificationCourseRepository} params.certificationCourseRepository
* @param {PlacementProfileService} params.placementProfileService
* @param {CertificationCenterRepository} params.certificationCenterRepository
* @param {UserRepository} params.userRepository
* @param {CertificationBadgesService} params.certificationBadgesService
* @param {LanguageService} params.languageService
* @param {AssessmentRepository} params.assessmentRepository
* @param {CertificationChallengesService} params.certificationChallengesService
* @param {VerifyCertificateCodeService} params.verifyCertificateCodeService
Expand All @@ -200,12 +191,25 @@ async function _startNewCertification({
assessmentRepository,
certificationCourseRepository,
certificationCenterRepository,
userRepository,
certificationChallengesService,
languageService,
placementProfileService,
certificationBadgesService,
verifyCertificateCodeService,
lang,
}) {
let lang;
if (SessionVersion.isV3(session.version)) {
const user = await userRepository.get(userId);
const isUserLanguageValid = _validateUserLanguage(languageService, user.lang);

if (!isUserLanguageValid) {
throw new LanguageNotSupportedError(user.lang);
}

lang = user.lang;
}

const challengesForCertification = [];

const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId: session.id });
Expand Down

0 comments on commit c6068b6

Please sign in to comment.