style: fix linting issues met Prettier
This commit is contained in:
parent
2f5bb333db
commit
fc92570282
16 changed files with 498 additions and 505 deletions
|
@ -66,7 +66,7 @@ export async function getLearningPaths(req: AuthenticatedRequest, res: Response)
|
|||
|
||||
if (req.auth) {
|
||||
const adminUsername = req.auth.username;
|
||||
const userLearningPaths = await learningPathService.getLearningPathsAdministratedBy(adminUsername) || [];
|
||||
const userLearningPaths = (await learningPathService.getLearningPathsAdministratedBy(adminUsername)) || [];
|
||||
allLearningPaths = apiLearningPaths.concat(userLearningPaths);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ export async function getLearningPaths(req: AuthenticatedRequest, res: Response)
|
|||
hruidList,
|
||||
language as Language,
|
||||
`HRUIDs: ${hruidList.join(', ')}`,
|
||||
forGroup,
|
||||
forGroup
|
||||
);
|
||||
res.json(learningPaths.data);
|
||||
}
|
||||
|
|
|
@ -7,10 +7,13 @@ import { LearningPathTransition } from '../../entities/content/learning-path-tra
|
|||
|
||||
export class LearningPathRepository extends DwengoEntityRepository<LearningPath> {
|
||||
public async findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
|
||||
return this.findOne({
|
||||
hruid: hruid,
|
||||
language: language,
|
||||
}, { populate: ['nodes', 'nodes.transitions', 'admins'] });
|
||||
return this.findOne(
|
||||
{
|
||||
hruid: hruid,
|
||||
language: language,
|
||||
},
|
||||
{ populate: ['nodes', 'nodes.transitions', 'admins'] }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,11 +4,7 @@ import { getLearningPathRepository } from '../../data/repositories.js';
|
|||
import learningObjectService from '../learning-objects/learning-object-service.js';
|
||||
import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js';
|
||||
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
|
||||
import {
|
||||
getLastSubmissionForGroup,
|
||||
idFromLearningPathNode,
|
||||
isTransitionPossible,
|
||||
} from './learning-path-personalization-util.js';
|
||||
import { getLastSubmissionForGroup, idFromLearningPathNode, isTransitionPossible } from './learning-path-personalization-util.js';
|
||||
import {
|
||||
FilteredLearningObject,
|
||||
LearningObjectNode,
|
||||
|
@ -41,9 +37,9 @@ async function getLearningObjectsForNodes(nodes: Collection<LearningPathNode>):
|
|||
version: node.version,
|
||||
language: node.language,
|
||||
})
|
||||
.then((learningObject) => [node, learningObject] as [LearningPathNode, FilteredLearningObject | null]),
|
||||
),
|
||||
),
|
||||
.then((learningObject) => [node, learningObject] as [LearningPathNode, FilteredLearningObject | null])
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Ignore all learning objects that cannot be found such that the rest of the learning path keeps working.
|
||||
|
@ -105,14 +101,14 @@ async function convertNode(
|
|||
node: LearningPathNode,
|
||||
learningObject: FilteredLearningObject,
|
||||
personalizedFor: Group | undefined,
|
||||
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
|
||||
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>
|
||||
): Promise<LearningObjectNode> {
|
||||
const lastSubmission = personalizedFor ? await getLastSubmissionForGroup(idFromLearningPathNode(node), personalizedFor) : null;
|
||||
const transitions = node.transitions
|
||||
.filter(
|
||||
(trans) =>
|
||||
!personalizedFor || // If we do not want a personalized learning path, keep all transitions
|
||||
isTransitionPossible(trans, optionalJsonStringToObject(lastSubmission?.content)), // Otherwise remove all transitions that aren't possible.
|
||||
isTransitionPossible(trans, optionalJsonStringToObject(lastSubmission?.content)) // Otherwise remove all transitions that aren't possible.
|
||||
)
|
||||
.map((trans, i) => {
|
||||
try {
|
||||
|
@ -145,10 +141,10 @@ async function convertNode(
|
|||
*/
|
||||
async function convertNodes(
|
||||
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
|
||||
personalizedFor?: Group,
|
||||
personalizedFor?: Group
|
||||
): Promise<LearningObjectNode[]> {
|
||||
const nodesPromise = Array.from(nodesToLearningObjects.entries()).map(async (entry) =>
|
||||
convertNode(entry[0], entry[1], personalizedFor, nodesToLearningObjects),
|
||||
convertNode(entry[0], entry[1], personalizedFor, nodesToLearningObjects)
|
||||
);
|
||||
return await Promise.all(nodesPromise);
|
||||
}
|
||||
|
@ -175,7 +171,7 @@ function optionalJsonStringToObject(jsonString?: string): object | null {
|
|||
function convertTransition(
|
||||
transition: LearningPathTransition,
|
||||
index: number,
|
||||
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
|
||||
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>
|
||||
): Transition {
|
||||
const nextNode = nodesToLearningObjects.get(transition.next);
|
||||
if (!nextNode) {
|
||||
|
@ -206,10 +202,10 @@ const databaseLearningPathProvider: LearningPathProvider = {
|
|||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const learningPaths = (await Promise.all(hruids.map(async (hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)))).filter(
|
||||
(learningPath) => learningPath !== null,
|
||||
(learningPath) => learningPath !== null
|
||||
);
|
||||
const filteredLearningPaths = await Promise.all(
|
||||
learningPaths.map(async (learningPath, index) => convertLearningPath(learningPath, index, personalizedFor)),
|
||||
learningPaths.map(async (learningPath, index) => convertLearningPath(learningPath, index, personalizedFor))
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
@ -19,7 +19,7 @@ async function addProgressToLearningPath(learningPath: LearningPath, personalize
|
|||
learningPath.nodes.map(async (node) => {
|
||||
const lastSubmission = personalizedFor ? await getLastSubmissionForGroup(idFromLearningObjectNode(node), personalizedFor) : null;
|
||||
node.done = Boolean(lastSubmission);
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
learningPath.num_nodes = learningPath.nodes.length;
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
import dwengoApiLearningPathProvider from './dwengo-api-learning-path-provider.js';
|
||||
import databaseLearningPathProvider from './database-learning-path-provider.js';
|
||||
import { envVars, getEnvVar } from '../../util/envVars.js';
|
||||
import {
|
||||
LearningObjectNode,
|
||||
LearningPath,
|
||||
LearningPathIdentifier,
|
||||
LearningPathResponse,
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { LearningObjectNode, LearningPath, LearningPathIdentifier, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { Group } from '../../entities/assignments/group.entity.js';
|
||||
import { LearningPath as LearningPathEntity } from '../../entities/content/learning-path.entity.js';
|
||||
|
@ -46,16 +41,16 @@ export function mapToLearningPath(dto: LearningPath, adminsDto: TeacherDTO[]): L
|
|||
startNode: nodeDto.start_node ?? false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
}),
|
||||
})
|
||||
);
|
||||
dto.nodes.forEach((nodeDto) => {
|
||||
const fromNode = nodes.find(
|
||||
(it) => it.learningObjectHruid === nodeDto.learningobject_hruid && it.language === nodeDto.language && it.version === nodeDto.version,
|
||||
(it) => it.learningObjectHruid === nodeDto.learningobject_hruid && it.language === nodeDto.language && it.version === nodeDto.version
|
||||
)!;
|
||||
const transitions = nodeDto.transitions.map((transDto, i) => {
|
||||
const toNode = nodes.find(
|
||||
(it) =>
|
||||
it.learningObjectHruid === transDto.next.hruid && it.language === transDto.next.language && it.version === transDto.next.version,
|
||||
it.learningObjectHruid === transDto.next.hruid && it.language === transDto.next.language && it.version === transDto.next.version
|
||||
);
|
||||
|
||||
if (toNode) {
|
||||
|
@ -99,7 +94,7 @@ const learningPathService = {
|
|||
nonUserContentHruids,
|
||||
language,
|
||||
source,
|
||||
personalizedFor,
|
||||
personalizedFor
|
||||
);
|
||||
|
||||
const result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []);
|
||||
|
@ -124,7 +119,7 @@ const learningPathService = {
|
|||
*/
|
||||
async searchLearningPaths(query: string, language: Language, personalizedFor?: Group): Promise<LearningPath[]> {
|
||||
const providerResponses = await Promise.all(
|
||||
allProviders.map(async (provider) => provider.searchLearningPaths(query, language, personalizedFor)),
|
||||
allProviders.map(async (provider) => provider.searchLearningPaths(query, language, personalizedFor))
|
||||
);
|
||||
return providerResponses.flat();
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue