From e361f50baa6401297ec0e86f14593c5f58490329 Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Sun, 22 Jun 2025 16:20:01 +0000
Subject: [PATCH] GS-2156

---
 app.js |   49 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/app.js b/app.js
index 45cbb9d..3db466b 100644
--- a/app.js
+++ b/app.js
@@ -37,27 +37,37 @@
 
 const searchLib = require("./lib/search")
 searchLib.doIndex().catch(console.error)
-fastify.get("/api/search/user", async function (req, res) {
-   console.log(req.query)
-   const search = req.query?.search
-   if (!search) {
-      return res.code(422).send({status: "error", msg: "no search"})
-   }
-   else {
-      console.log(search)
-      const data = await searchLib.search(search)
-      return res.send(data)
-   }
-})
+fastify
+   .get("/api/search/user", async function (req, res) {
+      console.log(req.query)
+      const search = req.query?.search
+      if (!search) {
+         return res.code(422).send({status: "error", msg: "no search"})
+      }
+      else {
+         console.log(search)
+         const data = await searchLib.search(search)
+         return res.send(data)
+      }
+   })
+   .post("/api/search/reindex", async function (req, res) {
+      console.log("REINDEX ++++")
+      const start = Date.now()
+      await searchLib.doIndex().catch(console.error)
+      return res.send({
+         status: "ok",
+         msg: `reindexed in ${Date.now() - start} ms`,
+      })
+   })
 
 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)
    })
@@ -99,6 +109,16 @@
       }
    })
 
+   .post("/api/user", async function (req, res) {
+      const user = req.body
+      const res2 = await libIlias.importIliasUser(user) // TODO import or update if already available
+      return res.send(res2)
+   })
+
+   .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))) {
@@ -109,7 +129,6 @@
          console.log(res2)
          return res.send(res2)
       }
-
    })
 
    /////// ref_id / obj_id  ////////////////////////////////////////////////////////////////

--
Gitblit v1.8.0