From 07d24fc7a08276076495d90e1e0274a141acddbd Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Thu, 08 Oct 2026 16:00:15 +0000
Subject: [PATCH] GS-2555

---
 lib/libIlias.js |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/lib/libIlias.js b/lib/libIlias.js
index 489d1da..37b4108 100644
--- a/lib/libIlias.js
+++ b/lib/libIlias.js
@@ -9,9 +9,13 @@
 /////////////////////////////////////////////////////////////////////////
 
 module.exports = {
+   ping,
+
    getUser,
 
    importIliasUser,
+
+   createKurs,
 
    anmelden,
    abmelden,
@@ -24,6 +28,17 @@
 }
 
 /////////////////////////////////////////////////////////////////////////
+
+async function ping() {
+   const sp = new URLSearchParams({
+      command: "ping",
+      token: iliastoken,
+   })
+   let url2 = `${url}?${sp.toString()}`
+   console.log("pinging url", url2)
+   const res = await fetch(url2, {method: "GET"})
+   return await res.json() //
+}
 
 /////// GET USER ////////////////////////////////////////////////////////////////
 async function getUser (usr_id) {
@@ -70,13 +85,16 @@
 
    const udfDef = await db.getUdf()
    const udfMap = _.keyBy(udfDef, "field_name")
-   user.udf = _.mapKeys(user.udf, function (value, key) {
+
+   // do not mutate the caller's user object
+   const user2 = _.cloneDeep(user)
+   user2.udf = _.mapKeys(user.udf, function (value, key) {
       return udfMap[key].field_id
    })
 
    const res = await fetch(url2, {
       method: "POST",
-      body: JSON.stringify(user)
+      body: JSON.stringify(user2)
    })
    const text = await res.text()
    try {
@@ -147,6 +165,22 @@
 //    }
 // }
 
+/////// KURS ////////////////////////////////////////////////////////////////
+
+async function createKurs(kurs) {
+   const sp = new URLSearchParams({
+      command: "createKurs",
+      token: iliastoken,
+   })
+   let url2 = `${url}?${sp.toString()}`
+   const res = await fetch(url2, {
+      method: "POST",
+      body: JSON.stringify(kurs),
+   })
+   return await res.json()
+}
+
+
 /////// Anmelden / Abmelden ////////////////////////////////////////////////////////////////
 
 async function anmelden (usr_id, course_id) {
@@ -175,3 +209,5 @@
    const res = await fetch(url2, {method: "DELETE"})
    return await res.json()
 }
+
+

--
Gitblit v1.8.0