Skip to content

Commit af47941

Browse files
wip
1 parent d170c19 commit af47941

7 files changed

Lines changed: 117 additions & 126 deletions

File tree

api/src/certification/configuration/application/certification-version-controller.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ const deleteCertificationVersion = async function (request, h) {
3131
return h.response().code(204);
3232
};
3333

34-
const createCertificationVersion = async function (request, h) {
34+
const createDraft = async function (request, h) {
3535
const { scope } = request.params;
3636
const { tubeIds } = request.payload.data.attributes;
3737

38-
const createdCertificationId = await usecases.createCertificationVersion({ scope, tubeIds });
38+
const draftVersionId = await usecases.createDraft({ scope, tubeIds });
3939

40-
return h.response({ data: { id: createdCertificationId, type: 'certification-version' } }).code(201);
40+
// todo serialize avec la méthode
41+
return h.response({ data: { id: draftVersionId, type: 'certification-versions' } }).code(201);
4142
};
4243

4344
const certificationVersionController = {
44-
createCertificationVersion,
45+
createDraft,
4546
getVersionById,
4647
deleteCertificationVersion,
4748
update,

api/src/certification/configuration/application/certification-version-route.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ const register = async function (server) {
138138
},
139139
}),
140140
},
141-
handler: certificationVersionController.createCertificationVersion,
141+
handler: certificationVersionController.createDraft,
142142
tags: ['api', 'admin'],
143143
notes: [
144144
'Cette route est restreinte aux utilisateurs authentifiés avec le rôle Super Admin',
145-
'Elle permet de créer une nouvelle version de référentiel de certification',
145+
"Elle permet de créer un nouveau millésime draft d'un référentiel de certification",
146146
],
147147
},
148148
},

api/src/certification/configuration/domain/models/Version.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import Joi from 'joi';
22

33
import { EntityValidationError } from '../../../../shared/domain/errors.js';
4+
import {
5+
DEFAULT_MINIMUM_ANSWERS_REQUIRED_TO_VALIDATE_A_CERTIFICATION,
6+
DEFAULT_PROBABILITY_TO_PICK_CHALLENGE,
7+
DEFAULT_SESSION_DURATION_MINUTES,
8+
} from '../../../shared/domain/constants.js';
49
import { FlashAssessmentAlgorithmConfiguration } from '../../../shared/domain/models/FlashAssessmentAlgorithmConfiguration.js';
510
import { SCOPES } from '../../../shared/domain/models/Scopes.js';
11+
import { FRAMEWORK_HISTORY_STATUSES } from '../read-models/FrameworkHistoryEntry.js';
612

713
export class Version {
814
static #schema = Joi.object({
@@ -18,6 +24,9 @@ export class Version {
1824
competencesScoringConfiguration: Joi.array().allow(null).optional(),
1925
challengesConfiguration: Joi.object().instance(FlashAssessmentAlgorithmConfiguration).required(),
2026
comments: Joi.string().allow(null).optional(),
27+
status: Joi.string()
28+
.required()
29+
.valid(...Object.values(FRAMEWORK_HISTORY_STATUSES)),
2130
});
2231

2332
/**
@@ -55,6 +64,7 @@ export class Version {
5564
this.competencesScoringConfiguration = competencesScoringConfiguration;
5665
this.challengesConfiguration = challengesConfiguration;
5766
this.comments = comments === '' ? null : comments;
67+
this.status = this.#computeStatus();
5868
this.#validate();
5969
}
6070

@@ -68,4 +78,27 @@ export class Version {
6878
update({ comments }) {
6979
this.comments = comments;
7080
}
81+
82+
#computeStatus() {
83+
if (this.expirationDate) return FRAMEWORK_HISTORY_STATUSES.ARCHIVED;
84+
if (this.startDate) return FRAMEWORK_HISTORY_STATUSES.ACTIVE;
85+
return FRAMEWORK_HISTORY_STATUSES.DRAFT;
86+
}
87+
88+
get challengesBetweenSameCompetence() {
89+
return this.challengesConfiguration.challengesBetweenSameCompetence;
90+
}
91+
92+
toDTO() {
93+
return {
94+
scope: this.scope,
95+
startDate: null,
96+
expirationDate: null,
97+
assessmentDuration: activeVersion?.assessmentDuration ?? DEFAULT_SESSION_DURATION_MINUTES,
98+
minimumAnswersRequiredToValidateACertification:
99+
activeVersion?.minimumAnswersRequiredToValidateACertification ??
100+
DEFAULT_MINIMUM_ANSWERS_REQUIRED_TO_VALIDATE_A_CERTIFICATION,
101+
challengesConfiguration: this.challengesConfiguration.toDTO(),
102+
};
103+
}
71104
}

api/src/certification/configuration/domain/usecases/create-certification-version.js

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @typedef {import ('../../../shared/domain/models/Scopes.js').SCOPES} SCOPES
3+
* @typedef {import ('./index.js').ChallengeRepository} ChallengeRepository
4+
* @typedef {import ('./index.js').VersionRepository} VersionRepository
5+
*/
6+
7+
import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js';
8+
import { ENGLISH_SPOKEN, FRENCH_FRANCE, FRENCH_SPOKEN } from '../../../../shared/domain/services/locale-service.js';
9+
import {
10+
DEFAULT_MINIMUM_ANSWERS_REQUIRED_TO_VALIDATE_A_CERTIFICATION,
11+
DEFAULT_PROBABILITY_TO_PICK_CHALLENGE,
12+
DEFAULT_SESSION_DURATION_MINUTES,
13+
} from '../../../shared/domain/constants.js';
14+
import { FlashAssessmentAlgorithmConfiguration } from '../../../shared/domain/models/FlashAssessmentAlgorithmConfiguration.js';
15+
import { SCOPES } from '../../../shared/domain/models/Scopes.js';
16+
import { Version } from '../models/Version.js';
17+
import { FRAMEWORK_HISTORY_STATUSES } from '../read-models/FrameworkHistoryEntry.js';
18+
19+
/**
20+
* @param {object} params
21+
* @param {SCOPES} params.scope
22+
* @param {Array<string>} params.tubeIds
23+
* @param {ChallengeRepository} params.challengeRepository
24+
* @param {VersionRepository} params.versionRepository
25+
*/
26+
export async function createDraft({ scope, tubeIds, challengeRepository, versionRepository }) {
27+
const allVersions = await versionRepository.findAll();
28+
const scopeVersions = allVersions.filter((version) => version.scope === scope);
29+
const hasDraft = scopeVersions.some((version) => version.status === FRAMEWORK_HISTORY_STATUSES.DRAFT);
30+
if (hasDraft) {
31+
throw new Error('NOPE');
32+
}
33+
34+
const activeVersion = scopeVersions.some((version) => version.status === FRAMEWORK_HISTORY_STATUSES.ACTIVE);
35+
const locales = scope === SCOPES.CORE ? [FRENCH_SPOKEN, ENGLISH_SPOKEN, FRENCH_FRANCE] : [FRENCH_FRANCE];
36+
const challengeIds = await challengeRepository.findValidatedIdsByTubeIdsAndLocales(tubeIds, locales);
37+
38+
const version = _buildNewVersion({
39+
scope,
40+
activeVersion,
41+
versionRepository,
42+
});
43+
44+
return DomainTransaction.execute(() => {
45+
return versionRepository.create({ version, challengeIds });
46+
});
47+
}
48+
49+
/**
50+
* @param {object} params
51+
* @param {SCOPES} params.scope
52+
* @param {Version} params.activeVersion
53+
*/
54+
const _buildNewVersion = ({ scope, activeVersion }) => {
55+
// todo mettre un build static version
56+
return new Version({
57+
scope,
58+
startDate: null,
59+
expirationDate: null,
60+
assessmentDuration: activeVersion?.assessmentDuration ?? DEFAULT_SESSION_DURATION_MINUTES,
61+
minimumAnswersRequiredToValidateACertification:
62+
activeVersion?.minimumAnswersRequiredToValidateACertification ??
63+
DEFAULT_MINIMUM_ANSWERS_REQUIRED_TO_VALIDATE_A_CERTIFICATION,
64+
challengesConfiguration: new FlashAssessmentAlgorithmConfiguration({
65+
challengesBetweenSameCompetence: activeVersion?.challengesBetweenSameCompetence ?? ,
66+
maximumAssessmentLength: 32,
67+
variationPercent: 1,
68+
defaultCandidateCapacity: 0,
69+
defaultProbabilityToPickChallenge: DEFAULT_PROBABILITY_TO_PICK_CHALLENGE,
70+
limitToOneQuestionPerTube: true,
71+
enablePassageByAllCompetences: true,
72+
}),
73+
});
74+
};

api/src/certification/configuration/domain/usecases/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as mailService from '../../../../../src/certification/shared/domain/services/mail-service.js';
22
import * as challengeRepository from '../../../../shared/infrastructure/repositories/challenge-repository.js';
3-
import * as skillRepository from '../../../../shared/infrastructure/repositories/skill-repository.js';
4-
import * as tubeRepository from '../../../../shared/infrastructure/repositories/tube-repository.js';
53
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
64
import * as targetProfileHistoryRepository from '../../../shared/infrastructure/repositories/target-profile-history-repository.js';
75
import * as activeCalibratedChallengeRepository from '../../infrastructure/repositories/active-calibrated-challenge-repository.js';
@@ -17,7 +15,7 @@ import * as ScoBlockedAccessDatesRepository from '../../infrastructure/repositor
1715
import * as versionRepository from '../../infrastructure/repositories/version-repository.js';
1816
import { attachBadges } from './attach-badges.js';
1917
import { calibrateFrameworkVersion } from './calibrate-framework-version.js';
20-
import { createCertificationVersion } from './create-certification-version.js';
18+
import { createDraft } from './create-draft.js';
2119
import { deleteCertificationVersion } from './delete-certification-version.js';
2220
import { exportScoWhitelist } from './export-sco-whitelist.js';
2321
import { findCertificationFrameworks } from './find-certification-frameworks.js';
@@ -49,8 +47,6 @@ import { updateVersion } from './update-version.js';
4947
* @typedef {learningContentRepository} LearningContentRepository
5048
* @typedef {mailService} MailService
5149
* @typedef {organizationRepository} OrganizationRepository
52-
* @typedef {skillRepository} SkillRepository
53-
* @typedef {tubeRepository} TubeRepository
5450
* @typedef {ScoBlockedAccessDatesRepository} ScoBlockedAccessDatesRepository
5551
* @typedef {versionRepository} VersionRepository
5652
**/
@@ -67,16 +63,14 @@ const dependencies = {
6763
learningContentRepository,
6864
mailService,
6965
organizationRepository,
70-
skillRepository,
7166
targetProfileHistoryRepository,
72-
tubeRepository,
7367
versionRepository,
7468
};
7569

7670
const usecasesWithoutInjectedDependencies = {
7771
attachBadges,
7872
calibrateFrameworkVersion,
79-
createCertificationVersion,
73+
createDraft,
8074
deleteCertificationVersion,
8175
exportScoWhitelist,
8276
findCertificationFrameworks,

api/tests/certification/configuration/unit/domain/usecases/create-certification-version_test.js renamed to api/tests/certification/configuration/unit/domain/usecases/create-draft_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sinon from 'sinon';
22

33
import { Version } from '../../../../../../src/certification/configuration/domain/models/Version.js';
4-
import { createCertificationVersion } from '../../../../../../src/certification/configuration/domain/usecases/create-certification-version.js';
4+
import { createDraft } from '../../../../../../src/certification/configuration/domain/usecases/create-draft.js';
55
import {
66
DEFAULT_MINIMUM_ANSWERS_REQUIRED_TO_VALIDATE_A_CERTIFICATION,
77
DEFAULT_SESSION_DURATION_MINUTES,

0 commit comments

Comments
 (0)