REST Service for POPCORN - ILIAS
alex
2025-06-19 7a2f304888c58f61cfd0a918ae9ea573a8d729ba
lib/libIlias.js
@@ -1,6 +1,8 @@
/* Lib for interacting with customized ILIAS php */
module.exports = {
   importIliasUser,
   deleteUser,
   deleteAllUsers,
   deleteTeilnahme,
@@ -11,9 +13,78 @@
const settings = require("../settings")
const {getObjIdFromRefId} = require("./db")
const db = require("./db")
const {url} = settings.ilias
const {url, iliastoken} = settings.ilias
/////////////////////////////////////////////////////////////////////////
/////// USER IMPORT ////////////////////////////////////////////////////////////////
/**
 * Format in POPCORN für SOAP; ausprobieren ob das hier auch funktioniert, v.a. die user-defined-fields
 * {
 *         Action: "Insert",
 *         login: formatSapNr(dbMa.sapNr),
 *         password: passGen(12),
 *         firstname: dbMa.vorname,
 *         lastname: dbMa.nachname,
 *         email: email,
 *         gender: mapSex[dbMa.geschlecht],
 *         // GS-1894: Azubis wird der Ausbildungsberuf auch als Abteilung angezeigt
 *         department: getDepartment(dbMa),
 *         institution: dbMa.markt.markt,
 *         roleIdGlobal: 4,
 *         userDefinedField: [
 *             {
 *                 name: "Markt",
 *                 value: dbMa.markt.markt,
 *             },
 *             {
 *                 name: "Marktnummer",
 *                 value: dbMa.markt.nr,
 *             },
 *             {
 *                 name: "Personalnummer",
 *                 value: formatSapNr(dbMa.sapNr),
 *             },
 *         ],
 *     }
 * @param user
 * @returns {Promise<any>}
 */
async function importIliasUser (user) {
   const sp = new URLSearchParams({
      command: "importUser",
      token: iliastoken,
   })
   let url2 = `${url}?${sp.toString()}`
   console.log(url2)
   const res = await fetch(url2, {
      method: "POST",
      body: JSON.stringify(user)
   })
   const data = await res.json()
   return data
   const text = await res.text()
   try {
      const json = JSON.parse(text)
      return json
   } catch (ex) {
      console.error(ex.message)
      console.log(text)
      throw ex
   }
   try {
      return data
   } catch (ex) {
      const text = await res.text()
      console.error(text)
      return false
   }
}
/////// USER DELETE ////////////////////////////////////////////////////////////////
async function deleteUser (obj_id, dry = false) {
   const sp = new URLSearchParams({
@@ -21,28 +92,33 @@
      obj_id,
      // dry: "1",
      dry: dry ? "1" : "0",
      token: iliastoken,
   })
   let url2 = `${url}?${sp.toString()}`
   const res = await fetch(url2, {method: "DELETE"})
   const data = await res.json()
   // TODO update search index
   return data //
}
async function deleteAllUsers () {
   const users = await db.getUsers()
   const {data: users} = await db.getUsers(0, 100000)
   const res = {
      command: "deleteAllUsers",
      start: new Date(),
      end: new Date(),
      duration: null,
      count: 0,
      userIds: [],
   }
   for (const user of users) {
      await deleteUser(user.usr_id)
      res.count += 1
      res.userIds.push(user.usr_id)
   }
   res.end = new Date()
   res.duration = res.end - res.start
   // TODO update search index
   return res
}
@@ -53,6 +129,7 @@
      obj_id,
      usr_id,
      dry: dry ? "1" : "0",
      token: iliastoken,
   })
   let url2 = `${url}?${sp.toString()}`
   console.log("libIlias.deleteTeilnahme >>>", url2)
@@ -65,3 +142,4 @@
      throw ex
   }
}