feat: toevoeging fallback language constante

This commit is contained in:
Gabriellvl 2025-03-01 18:31:38 +01:00
parent 008e2e1c2c
commit 6bb8c364b9
6 changed files with 12 additions and 8 deletions

View file

@ -6,3 +6,5 @@
// Dotenv.config();
export const DWENGO_API_BASE = 'https://dwengo.org/backend/api';
export const FALLBACK_LANG = "nl";

View file

@ -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<void> {
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({

View file

@ -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<void> {
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<voi
export async function getLearningPathsByTheme(req: Request, res: Response): Promise<void> {
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<void> {
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' });

View file

@ -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) => {

View file

@ -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";

View file

@ -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(