REST Service for POPCORN - ILIAS
alex
2025-11-28 21cfe68a2ac2304d9c034b9d247a61e9861af666
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const db = require("../lib/db")
const yargs = require("yargs")
const libIlias = require("../lib/libIlias")
const search = require("../lib/search")
 
/////////////////////////////////////////////////////////////////////////
 
const argv = yargs
   .usage("$0 <login>", "delete user <login>",)
   .strict()
   .parse()
 
console.log(`argv.ref_id=${argv.ref_id}`)
 
run(argv)
   .then(console.log)
   .catch(console.error)
   .finally(process.exit)
 
async function run ({login}) {
   let userIds = await search.search(String(login))
 
   if (userIds.length > 1) throw {msg: "result not distinct!", results: userIds}
   if (userIds.length === 0) throw {msg: "nothing found!", results: userIds}
 
   const usr_id = userIds[0]
   const user = await db.getUserByUserId(usr_id)
   console.log(user)
 
   const { Confirm } = require('enquirer');
   const prompt = new Confirm({
      name: 'question',
      message: `Delete user ${user.firstname} ${user.lastname} (${user.usr_id})`,
   });
   const doContinue = await prompt.run();
 
   if(doContinue) {
      return libIlias.deleteUser(usr_id)
   }
   else {
      return "nothing changed... bye bye!"
   }
}