diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index 594da4e..8378d30 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -6,6 +6,7 @@ import { ConversationsController } from "./ConversationsController"; import { SearchController } from "./SearchController"; import { GroupsController } from "./GroupsController"; import { NotificationsController } from "./NotificationsController"; +import { VirtualDirectoryController } from "./VirtualDirectoryController"; /** * Controllers routes @@ -140,4 +141,10 @@ export const Routes : Route[] = [ {path: "/notifications/count_all_news", cb: (h) => NotificationsController.CountAllNews(h)}, {path: "/notifications/get_list_unread", cb: (h) => NotificationsController.GetListUnread(h)}, + + + + // Virtual directory controller + {path: "/virtualDirectory/find", cb: (h) => VirtualDirectoryController.Find(h)}, + ] \ No newline at end of file diff --git a/src/controllers/VirtualDirectoryController.ts b/src/controllers/VirtualDirectoryController.ts new file mode 100644 index 0000000..ad4feae --- /dev/null +++ b/src/controllers/VirtualDirectoryController.ts @@ -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, + }) + } + +} \ No newline at end of file