/* Lib for interacting with customized ILIAS php */
|
|
module.exports = {
|
deleteUser,
|
deleteAllUsers,
|
deleteTeilnahme,
|
}
|
|
/////////////////////////////////////////////////////////////////////////
|
|
const settings = require("../settings")
|
const {getObjIdFromRefId} = require("./db")
|
const db = require("./db")
|
const {url} = settings.ilias
|
|
/////////////////////////////////////////////////////////////////////////
|
|
async function deleteUser (obj_id, dry = false) {
|
const sp = new URLSearchParams({
|
command: "deleteUser",
|
obj_id,
|
// dry: "1",
|
dry: dry ? "1" : "0",
|
})
|
let url2 = `${url}?${sp.toString()}`
|
const res = await fetch(url2, {method: "DELETE"})
|
const data = await res.json()
|
return data //
|
}
|
|
async function deleteAllUsers () {
|
const users = await db.getUsers()
|
const res = {
|
command: "deleteAllUsers",
|
start: new Date(),
|
end: new Date(),
|
duration: null,
|
count: 0,
|
}
|
for (const user of users) {
|
await deleteUser(user.usr_id)
|
res.count += 1
|
}
|
res.end = new Date()
|
res.duration = res.end - res.start
|
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
|
}
|
}
|