fix: format

This commit is contained in:
Gabriellvl 2025-02-26 20:29:53 +01:00
parent ab17e982c7
commit cfaae9ebe4
4 changed files with 185 additions and 104 deletions

View file

@ -1,7 +1,6 @@
import express, { Express, Response } from 'express'; import express, { Express, Response } from 'express';
import initORM from './orm.js'; import initORM from './orm.js';
import themeRoutes from "./routes/themes.js"; import themeRoutes from './routes/themes.js';
const app: Express = express(); const app: Express = express();
const port: string | number = process.env.PORT || 3000; const port: string | number = process.env.PORT || 3000;
@ -13,8 +12,7 @@ app.get('/', (_, res: Response) => {
}); });
}); });
app.use("/theme", themeRoutes); app.use('/theme', themeRoutes);
async function startServer() { async function startServer() {
await initORM(); await initORM();

View file

@ -1,8 +1,8 @@
import fs from "fs"; import fs from 'fs';
import path from "path"; import path from 'path';
import yaml from "js-yaml"; import yaml from 'js-yaml';
import { Request, Response } from "express"; import { Request, Response } from 'express';
import { themes } from "../data/themes.js"; import { themes } from '../data/themes.js';
interface Translations { interface Translations {
curricula_page: { curricula_page: {
@ -15,44 +15,51 @@ interface Translations {
*/ */
function loadTranslations(language: string): Translations { function loadTranslations(language: string): Translations {
try { try {
const filePath = path.join(process.cwd(), "_i18n", `${language}.yml`); const filePath = path.join(process.cwd(), '_i18n', `${language}.yml`);
const yamlFile = fs.readFileSync(filePath, "utf8"); const yamlFile = fs.readFileSync(filePath, 'utf8');
return yaml.load(yamlFile) as Translations; return yaml.load(yamlFile) as Translations;
} catch (error) { } catch (error) {
console.error(`Kan vertaling niet laden voor ${language}, fallback naar Nederlands`); console.error(
`Kan vertaling niet laden voor ${language}, fallback naar Nederlands`
);
console.error(error); console.error(error);
const fallbackPath = path.join(process.cwd(), "_i18n", "nl.yml"); const fallbackPath = path.join(process.cwd(), '_i18n', 'nl.yml');
return yaml.load(fs.readFileSync(fallbackPath, "utf8")) as Translations; return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as Translations;
} }
} }
/** /**
* GET /themes Haalt de lijst met thema's op inclusief vertalingen * GET /themes Haalt de lijst met thema's op inclusief vertalingen
*/ */
export function getThemes(req: Request, res: Response){ export function getThemes(req: Request, res: Response) {
const language = (req.query.language as string)?.toLowerCase() || "nl"; const language = (req.query.language as string)?.toLowerCase() || 'nl';
const translations = loadTranslations(language); const translations = loadTranslations(language);
const themeList = themes.map((theme) => {return { const themeList = themes.map((theme) => {
key: theme.title, return {
title: translations.curricula_page[theme.title]?.title || theme.title, key: theme.title,
description: translations.curricula_page[theme.title]?.description, title:
image: `https://dwengo.org/images/curricula/logo_${theme.title}.png` translations.curricula_page[theme.title]?.title || theme.title,
}}); description: translations.curricula_page[theme.title]?.description,
image: `https://dwengo.org/images/curricula/logo_${theme.title}.png`,
};
});
res.json(themeList); res.json(themeList);
}; }
/** /**
* GET /themes/:theme Geeft de HRUIDs terug voor een specifiek thema * GET /themes/:theme Geeft de HRUIDs terug voor een specifiek thema
*/ */
export function getThemeByTitle(req: Request, res: Response) { export function getThemeByTitle(req: Request, res: Response) {
const themeKey = req.params.theme; const themeKey = req.params.theme;
const theme = themes.find((t) => {return t.title === themeKey}); const theme = themes.find((t) => {
return t.title === themeKey;
});
if (theme) { if (theme) {
res.json(theme.hruids); res.json(theme.hruids);
} else { } else {
res.status(404).json({ error: "Thema niet gevonden" }); res.status(404).json({ error: 'Thema niet gevonden' });
} }
}; }

View file

@ -5,116 +5,192 @@ export interface Theme {
export const themes: Theme[] = [ export const themes: Theme[] = [
{ {
title: "kiks", title: 'kiks',
hruids: [ hruids: [
"pn_werking", "un_artificiele_intelligentie", "pn_klimaatverandering", 'pn_werking',
"kiks1_microscopie", "kiks2_practicum", "pn_digitalebeelden", 'un_artificiele_intelligentie',
"kiks3_dl_basis", "kiks4_dl_gevorderd", "kiks5_classificatie", 'pn_klimaatverandering',
"kiks6_regressie", "kiks7_ethiek", "kiks8_eindtermen" 'kiks1_microscopie',
] 'kiks2_practicum',
'pn_digitalebeelden',
'kiks3_dl_basis',
'kiks4_dl_gevorderd',
'kiks5_classificatie',
'kiks6_regressie',
'kiks7_ethiek',
'kiks8_eindtermen',
],
}, },
{ {
title: "art", title: 'art',
hruids: [ hruids: [
"pn_werking", "un_artificiele_intelligentie", "art1", "art2", "art3" 'pn_werking',
] 'un_artificiele_intelligentie',
'art1',
'art2',
'art3',
],
}, },
{ {
title: "socialrobot", title: 'socialrobot',
hruids: [ hruids: ['sr0_lkr', 'sr0_lln', 'sr1', 'sr2', 'sr3', 'sr4'],
"sr0_lkr", "sr0_lln", "sr1", "sr2", "sr3", "sr4"
]
}, },
{ {
title: "agriculture", title: 'agriculture',
hruids: [ hruids: [
"pn_werking", "un_artificiele_intelligentie", "agri_landbouw", "agri_lopendeband" 'pn_werking',
] 'un_artificiele_intelligentie',
'agri_landbouw',
'agri_lopendeband',
],
}, },
{ {
title: "wegostem", title: 'wegostem',
hruids: [ hruids: ['wegostem'],
"wegostem"
]
}, },
{ {
title: "computational_thinking", title: 'computational_thinking',
hruids: [ hruids: [
"ct1_concepten", "ct2_concreet", "ct3_voorbeelden", "ct6_cases", 'ct1_concepten',
"ct9_impact", "ct10_bebras", "ct8_eindtermen", "ct7_historiek", 'ct2_concreet',
"ct5_kijkwijzer", "ct4_evaluatiekader" 'ct3_voorbeelden',
] 'ct6_cases',
'ct9_impact',
'ct10_bebras',
'ct8_eindtermen',
'ct7_historiek',
'ct5_kijkwijzer',
'ct4_evaluatiekader',
],
}, },
{ {
title: "math_with_python", title: 'math_with_python',
hruids: [ hruids: [
"pn_werking", "maths_pythagoras", "maths_spreidingsdiagrammen", 'pn_werking',
"maths_rechten", "maths_lineaireregressie", "maths_epidemie", 'maths_pythagoras',
"pn_digitalebeelden", "maths_logica", "maths_parameters", 'maths_spreidingsdiagrammen',
"maths_parabolen", "pn_regressie", "maths7_grafen", "maths8_statistiek" 'maths_rechten',
] 'maths_lineaireregressie',
'maths_epidemie',
'pn_digitalebeelden',
'maths_logica',
'maths_parameters',
'maths_parabolen',
'pn_regressie',
'maths7_grafen',
'maths8_statistiek',
],
}, },
{ {
title: "python_programming", title: 'python_programming',
hruids: [ hruids: [
"pn_werking", "pn_datatypes", "pn_operatoren", "pn_structuren", 'pn_werking',
"pn_functies", "art2", "stem_insectbooks", "un_algoenprog" 'pn_datatypes',
] 'pn_operatoren',
'pn_structuren',
'pn_functies',
'art2',
'stem_insectbooks',
'un_algoenprog',
],
}, },
{ {
title: "stem", title: 'stem',
hruids: [ hruids: [
"pn_werking", "maths_spreidingsdiagrammen", "pn_digitalebeelden", 'pn_werking',
"maths_epidemie", "stem_ipadres", "pn_klimaatverandering", 'maths_spreidingsdiagrammen',
"stem_rechten", "stem_lineaireregressie", "stem_insectbooks" 'pn_digitalebeelden',
] 'maths_epidemie',
'stem_ipadres',
'pn_klimaatverandering',
'stem_rechten',
'stem_lineaireregressie',
'stem_insectbooks',
],
}, },
{ {
title: "care", title: 'care',
hruids: [ hruids: [
"pn_werking", "un_artificiele_intelligentie", "aiz1_zorg", "aiz2_grafen", 'pn_werking',
"aiz3_unplugged", "aiz4_eindtermen", "aiz5_triage" 'un_artificiele_intelligentie',
] 'aiz1_zorg',
'aiz2_grafen',
'aiz3_unplugged',
'aiz4_eindtermen',
'aiz5_triage',
],
}, },
{ {
title: "chatbot", title: 'chatbot',
hruids: [ hruids: [
"pn_werking", "un_artificiele_intelligentie", "cb5_chatbotunplugged", 'pn_werking',
"cb1_chatbot", "cb2_sentimentanalyse", "cb3_vervoegmachine", 'un_artificiele_intelligentie',
"cb4_eindtermen", "cb6" 'cb5_chatbotunplugged',
] 'cb1_chatbot',
'cb2_sentimentanalyse',
'cb3_vervoegmachine',
'cb4_eindtermen',
'cb6',
],
}, },
{ {
title: "physical_computing", title: 'physical_computing',
hruids: [ hruids: [
"pc_starttodwenguino", "pc_rijdenderobot", "pc_theremin", 'pc_starttodwenguino',
"pc_leerlijn_introductie", "pc_leerlijn_invoer_verwerking_uitvoer", 'pc_rijdenderobot',
"pc_leerlijn_basisprincipes_digitale_elektronica", 'pc_theremin',
"pc_leerlijn_grafisch_naar_tekstueel", "pc_leerlijn_basis_programmeren", 'pc_leerlijn_introductie',
"pc_leerlijn_van_µc_naar_plc", "pc_leerlijn_fiches_dwenguino", 'pc_leerlijn_invoer_verwerking_uitvoer',
"pc_leerlijn_seriele_monitor", "pc_leerlijn_bus_protocollen", 'pc_leerlijn_basisprincipes_digitale_elektronica',
"pc_leerlijn_wifi", "pc_leerlijn_fiches_arduino", 'pc_leerlijn_grafisch_naar_tekstueel',
"pc_leerlijn_project_lijnvolger", "pc_leerlijn_project_bluetooth", 'pc_leerlijn_basis_programmeren',
"pc_leerlijn_hddclock", "pc_leerlijn_fysica_valbeweging", 'pc_leerlijn_van_µc_naar_plc',
"pc_leerlijn_luchtkwaliteit", "pc_leerlijn_weerstation", 'pc_leerlijn_fiches_dwenguino',
"pc_leerlijn_g0", "pc_leerlijn_g1", "pc_leerlijn_g3", "pc_leerlijn_g4", 'pc_leerlijn_seriele_monitor',
"pc_leerlijn_g5" 'pc_leerlijn_bus_protocollen',
] 'pc_leerlijn_wifi',
'pc_leerlijn_fiches_arduino',
'pc_leerlijn_project_lijnvolger',
'pc_leerlijn_project_bluetooth',
'pc_leerlijn_hddclock',
'pc_leerlijn_fysica_valbeweging',
'pc_leerlijn_luchtkwaliteit',
'pc_leerlijn_weerstation',
'pc_leerlijn_g0',
'pc_leerlijn_g1',
'pc_leerlijn_g3',
'pc_leerlijn_g4',
'pc_leerlijn_g5',
],
}, },
{ {
title: "algorithms", title: 'algorithms',
hruids: [ hruids: [
"art2", "anm1", "anm2", "anm3", "anm4", "anm11", "anm12", "anm13", 'art2',
"anm14", "anm15", "anm16", "anm17", "maths_epidemie", "stem_insectbooks" 'anm1',
] 'anm2',
'anm3',
'anm4',
'anm11',
'anm12',
'anm13',
'anm14',
'anm15',
'anm16',
'anm17',
'maths_epidemie',
'stem_insectbooks',
],
}, },
{ {
title: "basics_ai", title: 'basics_ai',
hruids: [ hruids: [
"un_artificiele_intelligentie", "org-dwengo-waisda-taal-murder-mistery", 'un_artificiele_intelligentie',
"art1", "org-dwengo-waisda-beelden-emoties-herkennen", 'org-dwengo-waisda-taal-murder-mistery',
"org-dwengo-waisda-beelden-unplugged-fax-lp", 'art1',
"org-dwengo-waisda-beelden-teachable-machine" 'org-dwengo-waisda-beelden-emoties-herkennen',
] 'org-dwengo-waisda-beelden-unplugged-fax-lp',
} 'org-dwengo-waisda-beelden-teachable-machine',
],
},
]; ];

View file

@ -1,9 +1,9 @@
import express from "express"; import express from 'express';
import { getThemes, getThemeByTitle } from "../controllers/themes.js"; import { getThemes, getThemeByTitle } from '../controllers/themes.js';
const router = express.Router(); const router = express.Router();
router.get("/", getThemes); router.get('/', getThemes);
router.get("/:theme", getThemeByTitle); router.get('/:theme', getThemeByTitle);
export default router; export default router;