From 98aaeb1328c9f72ead37ff5fc20e97d59bbe4e7e Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Tue, 17 Jun 2025 14:58:56 +0000
Subject: [PATCH] GS-1843

---
 lib/libIlias.js |   53 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/lib/libIlias.js b/lib/libIlias.js
index 506aa7c..b3d02a9 100644
--- a/lib/libIlias.js
+++ b/lib/libIlias.js
@@ -2,11 +2,15 @@
 
 module.exports = {
    deleteUser,
+   deleteAllUsers,
+   deleteTeilnahme,
 }
 
 /////////////////////////////////////////////////////////////////////////
 
 const settings = require("../settings")
+const {getObjIdFromRefId} = require("./db")
+const db = require("./db")
 const {url} = settings.ilias
 
 /////////////////////////////////////////////////////////////////////////
@@ -15,12 +19,53 @@
    const sp = new URLSearchParams({
       command: "deleteUser",
       obj_id,
-      dry : dry ? "1" : "0",
+      // dry: "1",
+      dry: dry ? "1" : "0",
    })
    let url2 = `${url}?${sp.toString()}`
-   console.log("libIlias.deleteUser >>>", url2)
    const res = await fetch(url2, {method: "DELETE"})
-   // console.log(res)
    const data = await res.json()
-   return data
+   // TODO update search index
+   return data //
+}
+
+async function deleteAllUsers () {
+   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
+}
+
+async function deleteTeilnahme (ref_id, usr_id, dry = false) {
+   const {obj_id} = await getObjIdFromRefId(ref_id)
+   const sp = new URLSearchParams({
+      command: "deleteTeilnahme",
+      obj_id,
+      usr_id,
+      dry: dry ? "1" : "0",
+   })
+   let url2 = `${url}?${sp.toString()}`
+   console.log("libIlias.deleteTeilnahme >>>", url2)
+   let res
+   try {
+      res = await fetch(url2, {method: "DELETE"})
+      return await res.json()
+   } catch (ex) {
+      console.error(ex)
+      throw ex
+   }
 }

--
Gitblit v1.8.0