From 97e0f73d88d0b3ba3e905ec354a8490cfc79873f Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Fri, 06 Jun 2025 14:26:14 +0000
Subject: [PATCH] adding search
---
app.js | 52 ++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/app.js b/app.js
index f512971..7b99446 100644
--- a/app.js
+++ b/app.js
@@ -3,10 +3,11 @@
logger: true
})
const _ = require("lodash")
-const db = require("./lib/db")
-
-const settings = require("./settings")
const fs = require("node:fs")
+
+const db = require("./lib/db")
+const settings = require("./settings")
+const search = require("./lib/search.js")
/////////////////////////////////////////////////////////////////////////
@@ -27,7 +28,7 @@
return res.send({status: "error", error: "access denied"})
}
else {
- console.log("NO AUTH FOR ",req.url)
+ console.log("NO AUTH FOR ", req.url)
}
})
@@ -45,8 +46,8 @@
.get("/api/user/login/:login", async function (req, res) {
const {login} = req.params
const user = await db.getUserByLogin(login)
- if (user.length) {
- return res.send(user[0])
+ if (user) {
+ return res.send(user)
}
else {
return res.code(404).send({status: "error", msg: "not found"})
@@ -54,12 +55,26 @@
})
.get("/api/user/userid/:userid", async function (req, res) {
const {userid} = req.params
- if(!userid || isNaN(Number(userid))) {
+ if (!userid || isNaN(Number(userid))) {
return res.code(500).send({status: "error", msg: "userid error"})
}
const user = await db.getUserByUserId(userid)
if (user) {
return res.send(user)
+ }
+ else {
+ return res.code(404).send({status: "error", msg: "not found"})
+ }
+ })
+ .get("/api/user/teilnahmen/:userId", async function (req, res) {
+ let userId = req.params.userId
+ console.log(`--------${userId}-----------`, typeof userId)
+ if (!userId || isNaN(Number(userId))) {
+ return res.code(500).send({status: "error", msg: "userId error"})
+ }
+ const tn = await db.getUserTeilnahmen(userId)
+ if (tn) {
+ return res.send(tn)
}
else {
return res.code(404).send({status: "error", msg: "not found"})
@@ -90,6 +105,7 @@
})
/////// Kurs ////////////////////////////////////////////////////////////////
+
.get("/api/kurs", async function (req, res) {
let data = await db.getKurse()
if (data) {
@@ -111,7 +127,7 @@
})
.get("/api/kurs/items/:refId", async function (req, res) {
const {refId} = req.params
- let data = await db.getKursItems(refId)
+ let data = await db.getKursItems2(refId)
if (data) {
return res.send(data)
}
@@ -140,6 +156,26 @@
}
})
+/////// SEARCH ////////////////////////////////////////////////////////////////
+
+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)
+ }
+})
+
+/////// STATIC ////////////////////////////////////////////////////////////////
+
+
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'vue/dist'),
prefix: '/ui/', // optional: default '/'
--
Gitblit v1.8.0