mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-27 07:49:22 +00:00
33 lines
849 B
TypeScript
33 lines
849 B
TypeScript
|
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,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
}
|