| | |
| | | |
| | | fastify |
| | | /////// USER //////////////////////////////////////////////////////////////// |
| | | .get('/api/users', async function (req, res) { |
| | | .get('/api/user', async function (req, res) { |
| | | const {offset, limit, search} = req.query |
| | | const users = await db.getUsers(offset, limit, search) |
| | | return res.send(users) |
| | | }) |
| | | .get("/api/users/count", async function (req, res) { |
| | | .get("/api/user/count", async function (req, res) { |
| | | const count = await db.getUserCount() |
| | | return res.send(count) |
| | | }) |
| | |
| | | } |
| | | }) |
| | | |
| | | |
| | | .delete("/api/user", async function (req, res) { // DELETE ALL users |
| | | const res2 = await libIlias.deleteAllUsers() |
| | | return res.send(res2) |
| | | }) |
| | | .delete("/api/user/:usr_id", async function (req, res) { |
| | | const {usr_id} = req.params |
| | | if (!usr_id || isNaN(Number(usr_id))) { |
| | |
| | | console.log(res2) |
| | | return res.send(res2) |
| | | } |
| | | |
| | | }) |
| | | |
| | | /////// ref_id / obj_id //////////////////////////////////////////////////////////////// |
| | |
| | | |
| | | module.exports = { |
| | | deleteUser, |
| | | deleteAllUsers, |
| | | deleteTeilnahme, |
| | | } |
| | | |
| | |
| | | |
| | | const settings = require("../settings") |
| | | const {getObjIdFromRefId} = require("./db") |
| | | const db = require("./db") |
| | | const {url} = settings.ilias |
| | | |
| | | ///////////////////////////////////////////////////////////////////////// |
| | |
| | | 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({ |
| | |
| | | /////// USER //////////////////////////////////////////////////////////////// |
| | | |
| | | export async function getUsers (offset, limit, search) { |
| | | const res = await fetch(`${apiBase}/users?offset=${offset}&limit=${limit}&search=${search}&token=${apiToken.value}`) |
| | | const res = await fetch(`${apiBase}/user?offset=${offset}&limit=${limit}&search=${search}&token=${apiToken.value}`) |
| | | return res.json() |
| | | } |
| | | |