diff --git a/backend/src/config/config.ts b/backend/src/config.ts similarity index 83% rename from backend/src/config/config.ts rename to backend/src/config.ts index 84181070..2de2920b 100644 --- a/backend/src/config/config.ts +++ b/backend/src/config.ts @@ -6,3 +6,5 @@ // Dotenv.config(); export const DWENGO_API_BASE = 'https://dwengo.org/backend/api'; + +export const FALLBACK_LANG = "nl"; diff --git a/backend/src/controllers/learningObjects.ts b/backend/src/controllers/learningObjects.ts index f7640891..91a1a3b1 100644 --- a/backend/src/controllers/learningObjects.ts +++ b/backend/src/controllers/learningObjects.ts @@ -1,5 +1,6 @@ import { Request, Response } from 'express'; import { getLearningObjectsFromPath } from '../services/learningObjects.js'; +import {FALLBACK_LANG} from "../config"; export async function getAllLearningObjects( req: Request, @@ -7,7 +8,7 @@ export async function getAllLearningObjects( ): Promise { try { const { hruid } = req.params; - const language = (req.query.language as string) || 'nl'; // Default to Dutch; + const language = (req.query.language as string) || FALLBACK_LANG; if (!language) { res.status(400).json({ diff --git a/backend/src/controllers/learningPaths.ts b/backend/src/controllers/learningPaths.ts index 880858f3..cf084e2b 100644 --- a/backend/src/controllers/learningPaths.ts +++ b/backend/src/controllers/learningPaths.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; import { themes } from '../data/themes.js'; -import { DWENGO_API_BASE } from '../config/config.js'; +import {DWENGO_API_BASE, FALLBACK_LANG} from '../config.js'; import { fetchWithLogging } from "../util/apiHelper.js"; import { fetchLearningPaths } from "../services/learningPaths.js"; @@ -12,7 +12,7 @@ import { fetchLearningPaths } from "../services/learningPaths.js"; export async function getLearningPaths(req: Request, res: Response): Promise { try { const hruids = req.query.hruids; // Can be string or array - const language = (req.query.language as string) || 'nl'; + const language = (req.query.language as string) || FALLBACK_LANG; let hruidList: string[] = []; @@ -39,7 +39,7 @@ export async function getLearningPaths(req: Request, res: Response): Promise { try { const themeKey = req.params.theme; - const language = (req.query.language as string) || 'nl'; + const language = (req.query.language as string) || FALLBACK_LANG; const theme = themes.find((t) => t.title === themeKey); if (!theme) { @@ -65,7 +65,7 @@ export async function getLearningPathsByTheme(req: Request, res: Response): Prom export async function searchLearningPaths(req: Request, res: Response): Promise { try { const query = req.query.query as string; - const language = (req.query.language as string) || 'nl'; + const language = (req.query.language as string) || FALLBACK_LANG; if (!query) { res.status(400).json({ error: 'Missing search query' }); diff --git a/backend/src/controllers/themes.ts b/backend/src/controllers/themes.ts index d6c67107..f4e24369 100644 --- a/backend/src/controllers/themes.ts +++ b/backend/src/controllers/themes.ts @@ -3,6 +3,7 @@ import path from 'path'; import yaml from 'js-yaml'; import { Request, Response } from 'express'; import { themes } from '../data/themes.js'; +import {FALLBACK_LANG} from "../config"; interface Translations { curricula_page: { @@ -26,7 +27,7 @@ function loadTranslations(language: string): Translations { } export function getThemes(req: Request, res: Response) { - const language = (req.query.language as string)?.toLowerCase() || 'nl'; + const language = (req.query.language as string)?.toLowerCase() || FALLBACK_LANG; const translations = loadTranslations(language); const themeList = themes.map((theme) => { diff --git a/backend/src/services/learningObjects.ts b/backend/src/services/learningObjects.ts index 9e1bb3a7..e753ad26 100644 --- a/backend/src/services/learningObjects.ts +++ b/backend/src/services/learningObjects.ts @@ -1,4 +1,4 @@ -import { DWENGO_API_BASE } from '../config/config.js'; +import { DWENGO_API_BASE } from '../config.js'; import { fetchWithLogging } from "../util/apiHelper.js"; import {FilteredLearningObject, LearningObjectMetadata, LearningObjectNode} from "../interfaces/learningPath.js"; import {fetchLearningPaths} from "./learningPaths.js"; diff --git a/backend/src/services/learningPaths.ts b/backend/src/services/learningPaths.ts index a5a84b1d..0bff4f92 100644 --- a/backend/src/services/learningPaths.ts +++ b/backend/src/services/learningPaths.ts @@ -1,5 +1,5 @@ import { fetchWithLogging } from "../util/apiHelper.js"; -import { DWENGO_API_BASE } from "../config/config.js"; +import { DWENGO_API_BASE } from "../config.js"; import {LearningPath, LearningPathResponse} from "../interfaces/learningPath.js"; export async function fetchLearningPaths(