Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Prendre en compte les traductions pour le calcul des statistiques d'épreuves/acquis sur une compétence (PIX-12616) #762

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/lib/application/competences/competences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { competenceRepository, thematicRepository, tubeRepository, skillRepository, challengeRepository, tutorialRepository } from '../../infrastructure/repositories/index.js';
import { CompetenceOverview } from '../../domain/readmodels/index.js';
import { extractParameters } from '../../infrastructure/utils/query-params-utils.js';
import { competenceOverviewSerializer } from '../../infrastructure/serializers/jsonapi/index.js';

export async function getCompetenceOverview(request, h) {
let { locale } = extractParameters(request.query);
locale = locale ?? 'fr';

const competenceId = request.params.id;

const [
competence,
thematicsForCompetence,
tubesForCompetence,
skillsForCompetence,
challengesForCompetence,
] = await Promise.all([
competenceRepository.getById(competenceId),
thematicRepository.listByCompetenceId(competenceId),
tubeRepository.listByCompetenceId(competenceId),
skillRepository.listByCompetenceId(competenceId),
challengeRepository.listByCompetenceId(competenceId),
]);

const learningMoreTutoIds = skillsForCompetence.flatMap(({ learningMoreTutorialIds }) => learningMoreTutorialIds ?? []);
const tutoIds = skillsForCompetence.flatMap(({ tutorialIds }) => tutorialIds ?? []);
const tutorialsForCompetence = await tutorialRepository.getMany([...tutoIds, ...learningMoreTutoIds]);

const competenceOverview = CompetenceOverview.build({ locale, competence, thematicsForCompetence, tubesForCompetence, skillsForCompetence, challengesForCompetence, tutorialsForCompetence });

return h.response(competenceOverviewSerializer.serialize(competenceOverview));
}
15 changes: 15 additions & 0 deletions api/lib/application/competences/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as competences from './competences.js';

export async function register(server) {
server.route([
{
method: 'GET',
path: '/api/competences/{id}',
config: {
handler: competences.getCompetenceOverview,
},
},
]);
}

export const name = 'competences-api';
21 changes: 21 additions & 0 deletions api/lib/domain/models/Challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ export class Challenge {
return this.status === Challenge.STATUSES.PERIME;
}

get isPrototype() {
return this.genealogy === Challenge.GENEALOGIES.PROTOTYPE;
}

get isDeclinaison() {
return this.genealogy === Challenge.GENEALOGIES.DECLINAISON;
}

get isDeclinable() {
return this.declinable !== Challenge.DECLINABLES.NON;
}

get primaryLocale() {
return this.#primaryLocales[0];
}
Expand Down Expand Up @@ -263,6 +275,15 @@ export class Challenge {
return JSON.parse(JSON.stringify(this.#translations));
}

static get STATUSES() {
return {
VALIDE: 'validé',
PROPOSE: 'proposé',
ARCHIVE: 'archivé',
PERIME: 'périmé',
};
}

static getPrimaryLocale(locales) {
return Challenge.defaultLocales(locales)[0];
}
Expand Down
8 changes: 8 additions & 0 deletions api/lib/domain/models/LocalizedChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export class LocalizedChallenge {
return this.id === this.challengeId;
}

get isValide() {
return this.status === LocalizedChallenge.STATUSES.PLAY;
}

get isPropose() {
return this.status === LocalizedChallenge.STATUSES.PAUSE;
}

get defaultEmbedUrl() {
if (!this.#primaryEmbedUrl) return null;

Expand Down
16 changes: 16 additions & 0 deletions api/lib/domain/models/Skill.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export class Skill {
return 'skill';
}

static get WORKBENCH() {
return '@workbench';
}

get isWorkbench() {
return this.name === Skill.WORKBENCH;
}

get isLive() {
return [Skill.STATUSES.EN_CONSTRUCTION, Skill.STATUSES.ACTIF].includes(this.status);
}
Expand All @@ -82,6 +90,14 @@ export class Skill {
return this.status === Skill.STATUSES.ACTIF;
}

get isArchive() {
return this.status === Skill.STATUSES.ARCHIVE;
}

get isPerime() {
return this.status === Skill.STATUSES.PERIME;
}

cloneSkillAndChallenges({ tubeDestination, level, skillChallenges, tubeSkills, attachments, generateNewIdFnc }) {
const version = tubeSkills.filter((sk) => sk.level === level).length + 1;
const name = `${tubeDestination.name}${level}`;
Expand Down
10 changes: 9 additions & 1 deletion api/lib/domain/models/Thematic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class Thematic {
index,
airtableId,
competenceId,
tubeIds,
tubeIds = [],
}) {
this.id = id;
this.name_i18n = name_i18n;
Expand All @@ -14,4 +14,12 @@ export class Thematic {
this.competenceId = competenceId;
this.tubeIds = tubeIds;
}

static get WORKBENCH() {
return 'workbench';
}

get isWorkbench() {
return this.name_i18n['fr'].startsWith(Thematic.WORKBENCH);
}
}
2 changes: 2 additions & 0 deletions api/lib/domain/models/Tube.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export class Tube {
practicalTitle_i18n,
practicalDescription_i18n,
competenceId,
index,
}) {
this.id = id;
this.airtableId = airtableId;
this.name = name;
this.practicalTitle_i18n = practicalTitle_i18n;
this.practicalDescription_i18n = practicalDescription_i18n;
this.competenceId = competenceId;
this.index = index;
}
}
9 changes: 9 additions & 0 deletions api/lib/domain/models/Tutorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Tutorial {
constructor({
id,
locale,
}) {
this.id = id;
this.locale = locale;
}
}
1 change: 1 addition & 0 deletions api/lib/domain/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from './Skill.js';
export * from './StaticCourse.js';
export * from './Thematic.js';
export * from './Translation.js';
export * from './Tutorial.js';
export * from './User.js';
Loading