mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 21:39:22 +00:00
Add search support
This commit is contained in:
parent
3eac46ac55
commit
75c49ee136
@ -135,6 +135,8 @@ export const Routes : Route[] = [
|
|||||||
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
|
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
|
||||||
{path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy
|
{path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy
|
||||||
|
|
||||||
|
{path: "/search/global", cb: (h) => SearchController.SearchGlobal(h)},
|
||||||
|
|
||||||
|
|
||||||
// Groups controller
|
// Groups controller
|
||||||
{path: "/groups/create", cb: (h) => GroupsController.Create(h)},
|
{path: "/groups/create", cb: (h) => GroupsController.Create(h)},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { RequestHandler } from "../entities/RequestHandler";
|
import { RequestHandler } from "../entities/RequestHandler";
|
||||||
import { UserHelper } from "../helpers/UserHelper";
|
import { UserHelper } from "../helpers/UserHelper";
|
||||||
|
import { GroupsHelper } from "../helpers/GroupsHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search controller
|
* Search controller
|
||||||
@ -25,4 +26,31 @@ export class SearchController {
|
|||||||
h.send(list);
|
h.send(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a global search (search both groups & users)
|
||||||
|
*
|
||||||
|
* @param h Request handler
|
||||||
|
*/
|
||||||
|
public static async SearchGlobal(h: RequestHandler) {
|
||||||
|
const query = h.postString("query", 1);
|
||||||
|
const limit = 10;
|
||||||
|
|
||||||
|
const results = [];
|
||||||
|
|
||||||
|
// First, search for groups
|
||||||
|
const groups = await GroupsHelper.SearchGroup(query, limit);
|
||||||
|
groups.map((e) => ({
|
||||||
|
kind: "group",
|
||||||
|
id: e
|
||||||
|
})).forEach((el) => results.push(el));
|
||||||
|
|
||||||
|
// Then search for users
|
||||||
|
const users = await UserHelper.SearchUser(query, limit);
|
||||||
|
users.map((e) => ({
|
||||||
|
kind: "user",
|
||||||
|
id: e
|
||||||
|
})).forEach((el) => results.push(el));
|
||||||
|
|
||||||
|
h.send(results);
|
||||||
|
}
|
||||||
}
|
}
|
@ -144,6 +144,27 @@ export class GroupsHelper {
|
|||||||
return this.DbToGroupInfo(row);
|
return this.DbToGroupInfo(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for groups
|
||||||
|
*
|
||||||
|
* @param query The query
|
||||||
|
* @param limit LImit for the search
|
||||||
|
*/
|
||||||
|
public static async SearchGroup(query: string, limit: number = 10) : Promise<Array<number>> {
|
||||||
|
|
||||||
|
const results = await DatabaseHelper.Query({
|
||||||
|
table: GROUPS_LIST_TABLE,
|
||||||
|
|
||||||
|
customWhere: "name LIKE ? AND visibility != ?",
|
||||||
|
customWhereArgs: ["%"+query+"%", GroupVisibilityLevel.SECRETE_GROUP.toString()],
|
||||||
|
|
||||||
|
limit: limit,
|
||||||
|
fields: ["id"]
|
||||||
|
});
|
||||||
|
|
||||||
|
return results.map((e) => e.id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update (set) group settings
|
* Update (set) group settings
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user