chore(backend): Verwijder redundante methoden
This commit is contained in:
parent
edc52a559c
commit
2f5bb333db
6 changed files with 8 additions and 58 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.searchLearningPathsByAdmin([adminUsername], language as Language, forGroup) || [];
|
||||
const userLearningPaths = await learningPathService.getLearningPathsAdministratedBy(adminUsername) || [];
|
||||
allLearningPaths = apiLearningPaths.concat(userLearningPaths);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
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 { MatchMode } from '@dwengo-1/common/util/match-mode';
|
||||
import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
|
||||
import { Teacher } from '../../entities/users/teacher.entity';
|
||||
|
||||
export class LearningPathRepository extends DwengoEntityRepository<LearningPath> {
|
||||
public async findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
|
||||
|
@ -15,18 +13,6 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
|
|||
}, { populate: ['nodes', 'nodes.transitions', 'admins'] });
|
||||
}
|
||||
|
||||
public async findByAdmins(admins: Teacher[], language: Language, _matchMode?: MatchMode): Promise<LearningPath[]> {
|
||||
return this.findAll({
|
||||
where: {
|
||||
language: language,
|
||||
admins: {
|
||||
$in: admins,
|
||||
},
|
||||
},
|
||||
populate: ['nodes', 'nodes.transitions'],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all learning paths which have the given language and whose title OR description contains the
|
||||
* query string.
|
||||
|
|
|
@ -4,7 +4,11 @@ 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,
|
||||
|
@ -13,12 +17,10 @@ import {
|
|||
Transition,
|
||||
} from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { MatchMode } from '@dwengo-1/common/util/match-mode';
|
||||
import { Group } from '../../entities/assignments/group.entity';
|
||||
import { Collection } from '@mikro-orm/core';
|
||||
import { v4 } from 'uuid';
|
||||
import { getLogger } from '../../logging/initalize.js';
|
||||
import { Teacher } from '../../entities/users/teacher.entity';
|
||||
|
||||
const logger = getLogger();
|
||||
|
||||
|
@ -235,13 +237,6 @@ const databaseLearningPathProvider: LearningPathProvider = {
|
|||
const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language);
|
||||
return await Promise.all(searchResults.map(async (result, index) => convertLearningPath(result, index, personalizedFor)));
|
||||
},
|
||||
|
||||
async searchLearningPathsByAdmin(admins: Teacher[], language: Language, personalizedFor?: Group, matchMode?: MatchMode): Promise<LearningPath[]> {
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const searchResults = await learningPathRepo.findByAdmins(admins, language, matchMode);
|
||||
return await Promise.all(searchResults.map(async (result, index) => convertLearningPath(result, index, personalizedFor)));
|
||||
},
|
||||
};
|
||||
|
||||
export default databaseLearningPathProvider;
|
||||
|
|
|
@ -3,8 +3,6 @@ import { DWENGO_API_BASE } from '../../config.js';
|
|||
import { LearningPathProvider } from './learning-path-provider.js';
|
||||
import { getLogger, Logger } from '../../logging/initalize.js';
|
||||
import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
|
||||
import { Teacher } from '../../entities/users/teacher.entity';
|
||||
import { Language } from '@dwengo-1/common/util/language';
|
||||
import { Group } from '../../entities/assignments/group.entity.js';
|
||||
import { getLastSubmissionForGroup, idFromLearningObjectNode } from './learning-path-personalization-util.js';
|
||||
|
||||
|
@ -21,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;
|
||||
|
@ -78,16 +76,8 @@ const dwengoApiLearningPathProvider: LearningPathProvider = {
|
|||
},
|
||||
|
||||
async getLearningPathsAdministratedBy(_adminUsername: string) {
|
||||
return []; // Learning paths fetched from the Dwengo API cannot be administrated by a user.
|
||||
},
|
||||
|
||||
async searchLearningPathsByAdmin(admins: Teacher[], language: string): Promise<LearningPath[]> {
|
||||
if (!admins || admins.length === 0) {
|
||||
return this.searchLearningPaths('', language as Language);
|
||||
}
|
||||
|
||||
// Dwengo API does not have the concept of admins, so we cannot filter by them.
|
||||
return []
|
||||
return [];
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -22,9 +22,4 @@ export interface LearningPathProvider {
|
|||
* Get all learning paths which have the teacher with the given user as an administrator.
|
||||
*/
|
||||
getLearningPathsAdministratedBy(adminUsername: string): Promise<LearningPath[]>;
|
||||
|
||||
/**
|
||||
* Fetch the learning paths for the given admins from the data source.
|
||||
*/
|
||||
searchLearningPathsByAdmin(admins: Teacher[], language: Language, personalizedFor?: Group, matchMode?: MatchMode): Promise<LearningPath[]>;
|
||||
}
|
||||
|
|
|
@ -129,22 +129,6 @@ const learningPathService = {
|
|||
return providerResponses.flat();
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch the learning paths for the given admins from the data source.
|
||||
*/
|
||||
async searchLearningPathsByAdmin(adminsIds: string[], language: Language, personalizedFor?: Group): Promise<LearningPath[]> {
|
||||
const teacherRepo = getTeacherRepository();
|
||||
const admins = await Promise.all(
|
||||
adminsIds .map(async (adminId) => await teacherRepo.findByUsername(adminId))
|
||||
);
|
||||
const adminsNotNull: Teacher[] = admins.filter((admin) => admin !== undefined) as Teacher[];
|
||||
|
||||
const providerResponses = await Promise.all(
|
||||
allProviders.map(async (provider) => provider.searchLearningPathsByAdmin(adminsNotNull, language, personalizedFor)),
|
||||
);
|
||||
return providerResponses.flat();
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new learning path to the database.
|
||||
* @param dto Learning path DTO from which the learning path will be created.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue