feat(backend): Added skeleton for a database learning object/path provider.
This commit is contained in:
parent
cc6947dd3c
commit
2d9f17484c
5 changed files with 103 additions and 6 deletions
|
@ -1,5 +1,13 @@
|
|||
import {LearningPath, LearningPathResponse} from "../../interfaces/learning-content";
|
||||
import {
|
||||
LearningPath,
|
||||
LearningPathResponse
|
||||
} from "../../interfaces/learning-content";
|
||||
import dwengoApiLearningPathProvider from "./dwengo-api-learning-path-provider";
|
||||
import databaseLearningPathProvider from "./database-learning-path-provider";
|
||||
import {EnvVars, getEnvVar} from "../../util/envvars";
|
||||
|
||||
const userContentPrefix = getEnvVar(EnvVars.UserContentPrefix);
|
||||
const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider]
|
||||
|
||||
/**
|
||||
* Service providing access to data about learning paths from the appropriate data source (database or Dwengo-api)
|
||||
|
@ -8,15 +16,32 @@ const learningPathService = {
|
|||
/**
|
||||
* Fetch the learning paths with the given hruids from the data source.
|
||||
*/
|
||||
fetchLearningPaths(hruids: string[], language: string, source: string): Promise<LearningPathResponse> {
|
||||
return dwengoApiLearningPathProvider.fetchLearningPaths(hruids, language, source);
|
||||
async fetchLearningPaths(hruids: string[], language: string, source: string): Promise<LearningPathResponse> {
|
||||
const userContentHruids = hruids.filter(hruid => hruid.startsWith(userContentPrefix));
|
||||
const nonUserContentHruids = hruids.filter(hruid => !hruid.startsWith(userContentPrefix));
|
||||
|
||||
const userContentLearningPaths =
|
||||
await databaseLearningPathProvider.fetchLearningPaths(userContentHruids, language, source);
|
||||
const nonUserContentLearningPaths
|
||||
= await databaseLearningPathProvider.fetchLearningPaths(nonUserContentHruids, language, source);
|
||||
|
||||
return {
|
||||
data: (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []),
|
||||
source: source,
|
||||
success: userContentLearningPaths.success || nonUserContentLearningPaths.success
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Search learning paths in the data source using the given search string.
|
||||
*/
|
||||
searchLearningPaths(query: string, language: string): Promise<LearningPath[]> {
|
||||
return dwengoApiLearningPathProvider.searchLearningPaths(query, language);
|
||||
async searchLearningPaths(query: string, language: string): Promise<LearningPath[]> {
|
||||
const providerResponses = await Promise.all(
|
||||
allProviders.map(
|
||||
provider => provider.searchLearningPaths(query, language)
|
||||
)
|
||||
);
|
||||
return providerResponses.flat();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue