mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 16:45:16 +00:00
Can get information about a single conversation
This commit is contained in:
@ -20,6 +20,37 @@ export class ConversationsController {
|
||||
handler.send(list.map(c => this.ConversationToAPI(c)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a single conversation
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public static async GetInfoSingle(handler: RequestHandler) {
|
||||
const conversationID = await this.GetPostConversationId("conversationID", handler);
|
||||
const conv = await ConversationsHelper.GetSingle(conversationID);
|
||||
|
||||
if(!conv)
|
||||
throw Error("Could not get information about the conversation (but it should have been found though) !!");
|
||||
|
||||
handler.send(this.ConversationToAPI(conv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return safely a conversation ID specified in a $_POST Request
|
||||
*
|
||||
* @param name The name of the POST field containing the ID of the conversation
|
||||
* @param handler
|
||||
*/
|
||||
private static async GetPostConversationId(name : string, handler: RequestHandler) : Promise<number> {
|
||||
const convID = handler.postInt(name);
|
||||
|
||||
// Check out whether the user belongs to the conversation or not
|
||||
if(!await ConversationsHelper.DoesUsersBelongsTo(handler.getUserId(), convID))
|
||||
handler.error(401, "You are not allowed to perform queries on this conversation!");
|
||||
|
||||
return convID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a conversation object into an API entry
|
||||
*
|
||||
|
@ -48,4 +48,7 @@ export const Routes : Route[] = [
|
||||
|
||||
// Conversations controller
|
||||
{path: "/conversations/getList", cb: (h) => ConversationsController.GetList(h)},
|
||||
|
||||
{path: "/conversations/getInfoOne", cb: (h) => ConversationsController.GetInfoSingle(h)},
|
||||
{path: "/conversations/getInfosOne", cb: (h) => ConversationsController.GetInfoSingle(h)}, // Legacy
|
||||
]
|
Reference in New Issue
Block a user