1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Can find virtual directory

This commit is contained in:
Pierre HUBERT 2019-12-28 13:07:26 +01:00
parent e96cb38942
commit 90158000c2
2 changed files with 40 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { ConversationsController } from "./ConversationsController";
import { SearchController } from "./SearchController"; import { SearchController } from "./SearchController";
import { GroupsController } from "./GroupsController"; import { GroupsController } from "./GroupsController";
import { NotificationsController } from "./NotificationsController"; import { NotificationsController } from "./NotificationsController";
import { VirtualDirectoryController } from "./VirtualDirectoryController";
/** /**
* Controllers routes * Controllers routes
@ -140,4 +141,10 @@ export const Routes : Route[] = [
{path: "/notifications/count_all_news", cb: (h) => NotificationsController.CountAllNews(h)}, {path: "/notifications/count_all_news", cb: (h) => NotificationsController.CountAllNews(h)},
{path: "/notifications/get_list_unread", cb: (h) => NotificationsController.GetListUnread(h)}, {path: "/notifications/get_list_unread", cb: (h) => NotificationsController.GetListUnread(h)},
// Virtual directory controller
{path: "/virtualDirectory/find", cb: (h) => VirtualDirectoryController.Find(h)},
] ]

View File

@ -0,0 +1,33 @@
import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper";
import { GroupsHelper } from "../helpers/GroupsHelper";
/**
* Virtual directory controller
*
* @author Pierre HUBERT
*/
export class VirtualDirectoryController {
/**
* Find a group / user using a given virtual directory
*
* @param h Request handler
*/
public static async Find(h: RequestHandler) {
const virtualDirectory = h.postVirtualDirectory("directory");
const userID = await UserHelper.FindByFolder(virtualDirectory);
const groupID = await GroupsHelper.FindByVirtualDirectory(virtualDirectory);
if(userID < 1 && groupID < 1)
h.error(404, "Specified user / group virtual directory not found !")
h.send({
kind: userID >= 1 ? "user" : "group",
id: userID >= 1 ? userID : groupID,
})
}
}