feat(backend): PUSH, PUT en DELETE endpoints voor leerpaden aangemaakt.

This commit is contained in:
Gerald Schmittinger 2025-05-12 16:11:08 +02:00
parent 20c04370b5
commit 30ca3b70de
8 changed files with 186 additions and 44 deletions

View file

@ -28,6 +28,21 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
});
}
/**
* Returns all learning paths which have the user with the given username as an administrator.
*/
public async findAllByAdminUsername(adminUsername: string): Promise<LearningPath[]> {
return this.findAll({
where: {
admins: {
$contains: {
username: adminUsername
}
}
}
});
}
public createNode(nodeData: RequiredEntityData<LearningPathNode>): LearningPathNode {
return this.em.create(LearningPathNode, nodeData);
}
@ -50,4 +65,16 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
await Promise.all(nodes.map(async (it) => em.persistAndFlush(it)));
await Promise.all(transitions.map(async (it) => em.persistAndFlush(it)));
}
/**
* Deletes the learning path with the given hruid and language.
* @returns the deleted learning path or null if it was not found.
*/
public async deleteByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
const path = await this.findByHruidAndLanguage(hruid, language);
if (path) {
await this.em.removeAndFlush(path);
}
return path;
}
}