mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-07-14 21:58:05 +00:00
Can search users in the database
This commit is contained in:
@ -3,6 +3,7 @@ import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { AccountController } from "./AccountController";
|
||||
import { UserController } from "./UserController";
|
||||
import { ConversationsController } from "./ConversationsController";
|
||||
import { SearchController } from "./SearchController";
|
||||
|
||||
/**
|
||||
* Controllers routes
|
||||
@ -51,4 +52,9 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/conversations/getInfoOne", cb: (h) => ConversationsController.GetInfoSingle(h)},
|
||||
{path: "/conversations/getInfosOne", cb: (h) => ConversationsController.GetInfoSingle(h)}, // Legacy
|
||||
|
||||
|
||||
// Search controller
|
||||
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
|
||||
{path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy
|
||||
]
|
28
src/controllers/SearchController.ts
Normal file
28
src/controllers/SearchController.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
|
||||
/**
|
||||
* Search controller
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
export class SearchController {
|
||||
|
||||
/**
|
||||
* Search for user
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async SearchUser(h : RequestHandler) {
|
||||
|
||||
// Get request
|
||||
const query = h.postString("query", 1);
|
||||
const limit = h.postInt("searchLimit", 5);
|
||||
|
||||
const list = await UserHelper.SearchUser(query, limit);
|
||||
|
||||
h.send(list);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user