1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-27 07:49:22 +00:00
comunicapiv2/src/controllers/VirtualDirectoryController.ts

33 lines
849 B
TypeScript
Raw Normal View History

2019-12-28 12:07:26 +00:00
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,
})
}
}