fix: Test- en linting-errors opgelost
This commit is contained in:
parent
ce5c0ea629
commit
ba912c3ef0
20 changed files with 103 additions and 116 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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' })
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue