fix: Test- en linting-errors opgelost

This commit is contained in:
Gerald Schmittinger 2025-04-18 23:47:56 +02:00
parent ce5c0ea629
commit ba912c3ef0
20 changed files with 103 additions and 116 deletions

View file

@ -19,8 +19,7 @@ export async function getSubmissionsHandler(req: Request, res: Response): Promis
const forGroup = req.query.forGroup as string | undefined;
let submissions: SubmissionDTO[]
submissions = await getSubmissionsForLearningObjectAndAssignment(
const submissions: SubmissionDTO[] = await getSubmissionsForLearningObjectAndAssignment(
loHruid,
lang,
version,

View file

@ -61,28 +61,36 @@ export class SubmissionRepository extends DwengoEntityRepository<Submission> {
/**
* Looks up all submissions for the given learning object which were submitted as part of the given assignment.
* When forGroup is set, only the submissions of the given group are shown.
*/
public async findAllSubmissionsForLearningObjectAndAssignment(
loId: LearningObjectIdentifier,
assignment: Assignment,
forGroup?: number
): Promise<Submission[]> {
const onBehalfOf = forGroup
? {
assignment,
groupNumber: forGroup
}
: {
assignment,
};
return this.findAll({
where: {
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version,
onBehalfOf,
onBehalfOf: {
assignment
}
},
});
}
/**
* 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[]> {
return this.findAll({
where: {
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version,
onBehalfOf: group
},
});
}

View file

@ -29,13 +29,13 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
}
public createNode(
nodeData: RequiredEntityData<LearningPathNode, never, false>
nodeData: RequiredEntityData<LearningPathNode>
): LearningPathNode {
return this.em.create(LearningPathNode, nodeData);
}
public createTransition(
transitionData: RequiredEntityData<LearningPathTransition, never, false>
transitionData: RequiredEntityData<LearningPathTransition>
): LearningPathTransition {
return this.em.create(LearningPathTransition, transitionData)
}
@ -53,7 +53,7 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
}
const em = this.getEntityManager();
await em.persistAndFlush(path);
await Promise.all(nodes.map(it => em.persistAndFlush(it)));
await Promise.all(transitions.map(it => em.persistAndFlush(it)));
await Promise.all(nodes.map(async it => em.persistAndFlush(it)));
await Promise.all(transitions.map(async it => em.persistAndFlush(it)));
}
}

View file

@ -42,7 +42,7 @@ export class LearningObject {
@Property({ type: 'array' })
keywords: string[] = [];
@Property({ type: new ArrayType(i => +i), nullable: true })
@Property({ type: new ArrayType(i => Number(i)), nullable: true })
targetAges?: number[] = [];
@Property({ type: 'bool' })

View file

@ -61,9 +61,9 @@ export function mapToLearningPath(
next: toNode,
condition: transDto.condition ?? "true"
});
} else {
}
return undefined;
}
}).filter(it => it).map(it => it!);
fromNode.transitions = new Collection<LearningPathTransition>(fromNode, transitions);

View file

@ -1,4 +1,4 @@
import {getAssignmentRepository, 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';
@ -37,11 +37,8 @@ export async function createSubmission(submissionDTO: SubmissionDTO): Promise<Su
const submissionRepository = getSubmissionRepository();
const submission = mapToSubmission(submissionDTO, submitter, group);
try {
await submissionRepository.save(submission);
} catch (e) {
"test"
}
await submissionRepository.save(submission);
return mapToSubmissionDTO(submission);
}
@ -69,7 +66,13 @@ export async function getSubmissionsForLearningObjectAndAssignment(
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentId);
const submissions = await getSubmissionRepository().findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!, groupId);
let submissions: Submission[];
if (groupId !== undefined) {
const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, groupId);
submissions = await getSubmissionRepository().findAllSubmissionsForLearningObjectAndGroup(loId, group!);
} else {
submissions = await getSubmissionRepository().findAllSubmissionsForLearningObjectAndAssignment(loId, assignment!);
}
return submissions.map((s) => mapToSubmissionDTO(s));
}

View file

@ -27,7 +27,10 @@ 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]) {
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;

View file

@ -2,10 +2,10 @@
* Convert a Base64-encoded string into a buffer with the same data.
* @param base64 The Base64 encoded string.
*/
export function base64ToArrayBuffer(base64: string) {
var binaryString = atob(base64);
var bytes = new Uint8Array(binaryString.length);
for (var i = 0; i < binaryString.length; i++) {
export function base64ToArrayBuffer(base64: string): ArrayBuffer {
const binaryString = atob(base64);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;