REST Service for POPCORN - ILIAS
alex
5 hours ago c1d7cb100a522271a3957ced9813663d64bfccd4
adding  searchUsers.js
1 files added
38 ■■■■■ changed files
bin/searchUsers.js 38 ●●●●● patch | view | raw | blame | history
bin/searchUsers.js
New file
@@ -0,0 +1,38 @@
const db = require("../lib/db")
const searchLib = require("../lib/search")
const yargs = require("yargs")
/////////////////////////////////////////////////////////////////////////
const argv = yargs
   .usage("$0 <search> [offset] [limit]", "search users",)
   .option("ids-only", {
      describe: "only print matching usr_ids",
      type: "boolean",
      default: false,
   })
   .strict()
   .parse()
run(argv)
   .then(print)
   .catch(console.error)
   .finally(process.exit)
async function run({search, offset, limit, idsOnly}) {
   if (idsOnly) {
      return await searchLib.search(String(search))
   }
   offset = offset || 0
   limit = limit || 20
   return await db.getUsers(offset, limit, String(search))
}
function print (res) {
   if (Array.isArray(res)) {
      console.log(res)
      return
   }
   const {total, offset, limit, data} = res
   console.log({data, count: data.length, total, offset, limit})
}