adding in stuff to make search work but still testing and stuff

This commit is contained in:
talksik
2022-03-18 12:37:39 -04:00
parent 726ab29b64
commit 1ff61bf91d
12 changed files with 225 additions and 64 deletions
+40
View File
@@ -0,0 +1,40 @@
import express, { Application, Request, Response } from "express";
import SearchResponse from "@nirvana/core/responses/search.response";
import { User } from "@nirvana/core/models";
import { UserService } from "../services/user.service";
import { authCheck } from "../middleware/auth";
export default function getSearchRoutes() {
const router = express.Router();
router.use(express.json());
// get user details based on id token
router.get("/", authCheck, handleSearch);
return router;
}
async function handleSearch(req: Request, res: Response) {
try {
const { query } = req.query;
if (!query) {
res.status(400).send("No search query provided!");
return;
}
// text search on users
const users: User[] | null = await UserService.getUsersLikeEmailAndName(
query as string
);
const resObj = new SearchResponse(users ?? []);
res.send(resObj);
} catch (error) {
console.log(error);
res.status(500).send(`something went wrong`);
}
}