style: fix linting issues met Prettier
This commit is contained in:
parent
af8c783a26
commit
5168ceaee0
56 changed files with 680 additions and 741 deletions
|
@ -5,8 +5,8 @@ import learningPathService from '../services/learning-paths/learning-path-servic
|
|||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import {Group} from "../entities/assignments/group.entity";
|
||||
import {getAssignmentRepository, getGroupRepository} from "../data/repositories";
|
||||
import { Group } from '../entities/assignments/group.entity';
|
||||
import { getAssignmentRepository, getGroupRepository } from '../data/repositories';
|
||||
|
||||
/**
|
||||
* Fetch learning paths based on query parameters.
|
||||
|
@ -27,13 +27,9 @@ export async function getLearningPaths(req: Request, res: Response): Promise<voi
|
|||
if (!assignmentNo || !classId) {
|
||||
throw new BadRequestException('If forGroupNo is specified, assignmentNo and classId must also be specified.');
|
||||
}
|
||||
const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(
|
||||
classId, parseInt(assignmentNo)
|
||||
);
|
||||
const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, parseInt(assignmentNo));
|
||||
if (assignment) {
|
||||
forGroup = await getGroupRepository().findByAssignmentAndGroupNumber(
|
||||
assignment, parseInt(forGroupNo)
|
||||
) ?? undefined;
|
||||
forGroup = (await getGroupRepository().findByAssignmentAndGroupNumber(assignment, parseInt(forGroupNo))) ?? undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,11 +52,6 @@ export async function getLearningPaths(req: Request, res: Response): Promise<voi
|
|||
hruidList = themes.flatMap((theme) => theme.hruids);
|
||||
}
|
||||
|
||||
const learningPaths = await learningPathService.fetchLearningPaths(
|
||||
hruidList,
|
||||
language as Language,
|
||||
`HRUIDs: ${hruidList.join(', ')}`,
|
||||
forGroup
|
||||
);
|
||||
const learningPaths = await learningPathService.fetchLearningPaths(hruidList, language as Language, `HRUIDs: ${hruidList.join(', ')}`, forGroup);
|
||||
res.json(learningPaths.data);
|
||||
}
|
||||
|
|
|
@ -62,18 +62,15 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
/**
|
||||
* Looks up all submissions for the given learning object which were submitted as part of the given assignment.
|
||||
*/
|
||||
public async findAllSubmissionsForLearningObjectAndAssignment(
|
||||
loId: LearningObjectIdentifier,
|
||||
assignment: Assignment,
|
||||
): Promise<Submission[]> {
|
||||
public async findAllSubmissionsForLearningObjectAndAssignment(loId: LearningObjectIdentifier, assignment: Assignment): Promise<Submission[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
learningObjectVersion: loId.version,
|
||||
onBehalfOf: {
|
||||
assignment
|
||||
}
|
||||
assignment,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -81,16 +78,13 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
|
|||
/**
|
||||
* Looks up all submissions for the given learning object which were submitted by the given group
|
||||
*/
|
||||
public async findAllSubmissionsForLearningObjectAndGroup(
|
||||
loId: LearningObjectIdentifier,
|
||||
group: Group,
|
||||
): Promise<Submission[]> {
|
||||
public async findAllSubmissionsForLearningObjectAndGroup(loId: LearningObjectIdentifier, group: Group): Promise<Submission[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
learningObjectHruid: loId.hruid,
|
||||
learningObjectLanguage: loId.language,
|
||||
learningObjectVersion: loId.version,
|
||||
onBehalfOf: group
|
||||
onBehalfOf: group,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
|
||||
import { LearningPath } from '../../entities/content/learning-path.entity.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import {LearningPathNode} from "../../entities/content/learning-path-node.entity";
|
||||
import {RequiredEntityData} from "@mikro-orm/core";
|
||||
import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity";
|
||||
import {EntityAlreadyExistsException} from "../../exceptions/entity-already-exists-exception";
|
||||
import { LearningPathNode } from '../../entities/content/learning-path-node.entity';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity';
|
||||
import { EntityAlreadyExistsException } from '../../exceptions/entity-already-exists-exception';
|
||||
|
||||
export class LearningPathRepository extends DwengoEntityRepository<LearningPath> {
|
||||
public async findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
|
||||
|
@ -28,32 +28,26 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
|
|||
});
|
||||
}
|
||||
|
||||
public createNode(
|
||||
nodeData: RequiredEntityData<LearningPathNode>
|
||||
): LearningPathNode {
|
||||
public createNode(nodeData: RequiredEntityData<LearningPathNode>): LearningPathNode {
|
||||
return this.em.create(LearningPathNode, nodeData);
|
||||
}
|
||||
|
||||
public createTransition(
|
||||
transitionData: RequiredEntityData<LearningPathTransition>
|
||||
): LearningPathTransition {
|
||||
return this.em.create(LearningPathTransition, transitionData)
|
||||
public createTransition(transitionData: RequiredEntityData<LearningPathTransition>): LearningPathTransition {
|
||||
return this.em.create(LearningPathTransition, transitionData);
|
||||
}
|
||||
|
||||
public async saveLearningPathNodesAndTransitions(
|
||||
path: LearningPath,
|
||||
nodes: LearningPathNode[],
|
||||
transitions: LearningPathTransition[],
|
||||
options?: {preventOverwrite?: boolean}
|
||||
options?: { preventOverwrite?: boolean }
|
||||
): Promise<void> {
|
||||
if (options?.preventOverwrite && (await this.findOne(path))) {
|
||||
throw new EntityAlreadyExistsException(
|
||||
"A learning path with this hruid/language combination already exists."
|
||||
);
|
||||
throw new EntityAlreadyExistsException('A learning path with this hruid/language combination already exists.');
|
||||
}
|
||||
const em = this.getEntityManager();
|
||||
await em.persistAndFlush(path);
|
||||
await Promise.all(nodes.map(async it => em.persistAndFlush(it)));
|
||||
await Promise.all(transitions.map(async it => em.persistAndFlush(it)));
|
||||
await Promise.all(nodes.map(async (it) => em.persistAndFlush(it)));
|
||||
await Promise.all(transitions.map(async (it) => em.persistAndFlush(it)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {ArrayType, Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property} from '@mikro-orm/core';
|
||||
import { ArrayType, Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Attachment } from './attachment.entity.js';
|
||||
import { Teacher } from '../users/teacher.entity.js';
|
||||
import { DwengoContentType } from '../../services/learning-objects/processing/content-type.js';
|
||||
|
@ -42,7 +42,7 @@ export class LearningObject {
|
|||
@Property({ type: 'array' })
|
||||
keywords: string[] = [];
|
||||
|
||||
@Property({ type: new ArrayType(i => Number(i)), nullable: true })
|
||||
@Property({ type: new ArrayType((i) => Number(i)), nullable: true })
|
||||
targetAges?: number[] = [];
|
||||
|
||||
@Property({ type: 'bool' })
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property, Rel} from '@mikro-orm/core';
|
||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property, Rel } from '@mikro-orm/core';
|
||||
import { LearningPath } from './learning-path.entity.js';
|
||||
import { LearningPathTransition } from './learning-path-transition.entity.js';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Collection, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property} from '@mikro-orm/core';
|
||||
import { Collection, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Teacher } from '../users/teacher.entity.js';
|
||||
import { LearningPathRepository } from '../../data/content/learning-path-repository.js';
|
||||
import { LearningPathNode } from './learning-path-node.entity.js';
|
||||
|
|
|
@ -9,7 +9,7 @@ export function errorHandler(err: unknown, _req: Request, res: Response, _: Next
|
|||
logger.warn(`An error occurred while handling a request: ${err} (-> HTTP ${err.status})`);
|
||||
res.status(err.status).json(err);
|
||||
} else {
|
||||
logger.error(`Unexpected error occurred while handing a request: ${(err as {stack: string})?.stack ?? JSON.stringify(err)}`);
|
||||
logger.error(`Unexpected error occurred while handing a request: ${(err as { stack: string })?.stack ?? JSON.stringify(err)}`);
|
||||
res.status(500).json(err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
LearningPathResponse,
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
import {v4} from "uuid";
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject {
|
||||
return {
|
||||
|
|
|
@ -32,8 +32,7 @@ function convertLearningObject(learningObject: LearningObject | null): FilteredL
|
|||
educationalGoals: learningObject.educationalGoals,
|
||||
returnValue: {
|
||||
callback_url: learningObject.returnValue.callbackUrl,
|
||||
callback_schema: learningObject.returnValue.callbackSchema === "" ? ""
|
||||
: JSON.parse(learningObject.returnValue.callbackSchema),
|
||||
callback_schema: learningObject.returnValue.callbackSchema === '' ? '' : JSON.parse(learningObject.returnValue.callbackSchema),
|
||||
},
|
||||
skosConcepts: learningObject.skosConcepts,
|
||||
targetAges: learningObject.targetAges || [],
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
LearningPathIdentifier,
|
||||
LearningPathResponse,
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import {v4} from "uuid";
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ import {
|
|||
Transition,
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import {Group} from "../../entities/assignments/group.entity";
|
||||
import {Collection} from "@mikro-orm/core";
|
||||
import {v4} from "uuid";
|
||||
import { Group } from '../../entities/assignments/group.entity';
|
||||
import { Collection } from '@mikro-orm/core';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
/**
|
||||
* Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its
|
||||
|
@ -165,7 +165,7 @@ function convertTransition(
|
|||
_id: String(index), // Retained for backwards compatibility. The index uniquely identifies the transition within the learning path.
|
||||
default: false, // We don't work with default transitions but retain this for backwards compatibility.
|
||||
next: {
|
||||
_id: nextNode._id ? (nextNode._id + index) : v4(), // Construct a unique ID for the transition for backwards compatibility.
|
||||
_id: nextNode._id ? nextNode._id + index : v4(), // Construct a unique ID for the transition for backwards compatibility.
|
||||
hruid: transition.next.learningObjectHruid,
|
||||
language: nextNode.language,
|
||||
version: nextNode.version,
|
||||
|
@ -181,12 +181,7 @@ const databaseLearningPathProvider: LearningPathProvider = {
|
|||
/**
|
||||
* Fetch the learning paths with the given hruids from the database.
|
||||
*/
|
||||
async fetchLearningPaths(
|
||||
hruids: string[],
|
||||
language: Language,
|
||||
source: string,
|
||||
personalizedFor?: Group
|
||||
): Promise<LearningPathResponse> {
|
||||
async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: Group): Promise<LearningPathResponse> {
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const learningPaths = (await Promise.all(hruids.map(async (hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)))).filter(
|
||||
|
@ -211,7 +206,7 @@ const databaseLearningPathProvider: LearningPathProvider = {
|
|||
|
||||
const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language);
|
||||
return await Promise.all(searchResults.map(async (result, index) => convertLearningPath(result, index, personalizedFor)));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default databaseLearningPathProvider;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { Group } from "../../entities/assignments/group.entity";
|
||||
import { Group } from '../../entities/assignments/group.entity';
|
||||
|
||||
/**
|
||||
* Generic interface for a service which provides access to learning paths from a data source.
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
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, LearningPathResponse} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { LearningObjectNode, LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import {Group} from "../../entities/assignments/group.entity";
|
||||
import {LearningPath as LearningPathEntity} from "../../entities/content/learning-path.entity";
|
||||
import {getLearningPathRepository} from "../../data/repositories";
|
||||
import {LearningPathNode} from "../../entities/content/learning-path-node.entity";
|
||||
import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity";
|
||||
import {base64ToArrayBuffer} from "../../util/base64-buffer-conversion";
|
||||
import {TeacherDTO} from "@dwengo-1/common/interfaces/teacher";
|
||||
import {mapToTeacher} from "../../interfaces/teacher";
|
||||
import {Collection} from "@mikro-orm/core";
|
||||
import { Group } from '../../entities/assignments/group.entity';
|
||||
import { LearningPath as LearningPathEntity } from '../../entities/content/learning-path.entity';
|
||||
import { getLearningPathRepository } from '../../data/repositories';
|
||||
import { LearningPathNode } from '../../entities/content/learning-path-node.entity';
|
||||
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity';
|
||||
import { base64ToArrayBuffer } from '../../util/base64-buffer-conversion';
|
||||
import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher';
|
||||
import { mapToTeacher } from '../../interfaces/teacher';
|
||||
import { Collection } from '@mikro-orm/core';
|
||||
|
||||
const userContentPrefix = getEnvVar(envVars.UserContentPrefix);
|
||||
const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider];
|
||||
|
||||
export function mapToLearningPath(
|
||||
dto: LearningPath, adminsDto: TeacherDTO[]
|
||||
): LearningPathEntity {
|
||||
const admins = adminsDto.map(admin => mapToTeacher(admin));
|
||||
export function mapToLearningPath(dto: LearningPath, adminsDto: TeacherDTO[]): LearningPathEntity {
|
||||
const admins = adminsDto.map((admin) => mapToTeacher(admin));
|
||||
const repo = getLearningPathRepository();
|
||||
const path = repo.create({
|
||||
hruid: dto.hruid,
|
||||
|
@ -27,7 +25,7 @@ export function mapToLearningPath(
|
|||
description: dto.description,
|
||||
title: dto.title,
|
||||
admins,
|
||||
image: dto.image ? Buffer.from(base64ToArrayBuffer(dto.image)) : null
|
||||
image: dto.image ? Buffer.from(base64ToArrayBuffer(dto.image)) : null,
|
||||
});
|
||||
const nodes = dto.nodes.map((nodeDto: LearningObjectNode, i: number) =>
|
||||
repo.createNode({
|
||||
|
@ -38,33 +36,34 @@ export function mapToLearningPath(
|
|||
version: nodeDto.version,
|
||||
startNode: nodeDto.start_node ?? false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: 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
|
||||
dto.nodes.forEach((nodeDto) => {
|
||||
const fromNode = nodes.find(
|
||||
(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
|
||||
);
|
||||
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
|
||||
);
|
||||
|
||||
if (toNode) {
|
||||
return repo.createTransition({
|
||||
transitionNumber: i,
|
||||
node: fromNode,
|
||||
next: toNode,
|
||||
condition: transDto.condition ?? "true"
|
||||
});
|
||||
}
|
||||
if (toNode) {
|
||||
return repo.createTransition({
|
||||
transitionNumber: i,
|
||||
node: fromNode,
|
||||
next: toNode,
|
||||
condition: transDto.condition ?? 'true',
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
|
||||
}).filter(it => it).map(it => it!);
|
||||
})
|
||||
.filter((it) => it)
|
||||
.map((it) => it!);
|
||||
|
||||
fromNode.transitions = new Collection<LearningPathTransition>(fromNode, transitions);
|
||||
});
|
||||
|
@ -85,12 +84,7 @@ const learningPathService = {
|
|||
* @param source
|
||||
* @param personalizedFor If this is set, a learning path personalized for the given group or student will be returned.
|
||||
*/
|
||||
async fetchLearningPaths(
|
||||
hruids: string[],
|
||||
language: Language,
|
||||
source: string,
|
||||
personalizedFor?: Group
|
||||
): Promise<LearningPathResponse> {
|
||||
async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: Group): Promise<LearningPathResponse> {
|
||||
const userContentHruids = hruids.filter((hruid) => hruid.startsWith(userContentPrefix));
|
||||
const nonUserContentHruids = hruids.filter((hruid) => !hruid.startsWith(userContentPrefix));
|
||||
|
||||
|
@ -129,8 +123,8 @@ const learningPathService = {
|
|||
async createNewLearningPath(dto: LearningPath, admins: TeacherDTO[]): Promise<void> {
|
||||
const repo = getLearningPathRepository();
|
||||
const path = mapToLearningPath(dto, admins);
|
||||
await repo.save(path, {preventOverwrite: true})
|
||||
}
|
||||
await repo.save(path, { preventOverwrite: true });
|
||||
},
|
||||
};
|
||||
|
||||
export default learningPathService;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {getAssignmentRepository, getGroupRepository, getSubmissionRepository} from '../data/repositories.js';
|
||||
import { getAssignmentRepository, getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
|
||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||
import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js';
|
||||
|
|
|
@ -27,10 +27,7 @@ export class SqliteAutoincrementSubscriber implements EventSubscriber {
|
|||
|
||||
for (const prop of Object.values(args.meta.properties)) {
|
||||
const property = prop as EntityProperty<T>;
|
||||
if (
|
||||
property.primary && property.autoincrement
|
||||
&& (args.entity as Record<string, unknown>)[property.name] === undefined
|
||||
) {
|
||||
if (property.primary && property.autoincrement && (args.entity as Record<string, unknown>)[property.name] === undefined) {
|
||||
// Obtain and increment sequence number of this entity.
|
||||
const propertyKey = args.meta.class.name + '.' + property.name;
|
||||
const nextSeqNumber = this.sequenceNumbersForEntityType.get(propertyKey) || 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue