1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 08:35:17 +00:00

Can create conversations

This commit is contained in:
2019-11-30 10:11:51 +01:00
parent b6739473a2
commit 3db123cd1e
7 changed files with 134 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import { RequestHandler } from "../entities/RequestHandler";
import { ConversationsHelper } from "../helpers/ConversationsHelper";
import { Conversation } from "../entities/Conversation";
import { Conversation, BaseConversation } from "../entities/Conversation";
import { UserHelper } from "../helpers/UserHelper";
/**
* Conversations controller
@ -10,6 +11,42 @@ import { Conversation } from "../entities/Conversation";
export class ConversationsController {
/**
* Create a new conversation
*
* @param h Request handler
*/
public static async CreateConversation(h : RequestHandler) {
const name = h.postString("name");
const members = h.postNumbersList("users");
// Check if the users exists
for (const userID of members) {
if(!await UserHelper.Exists(userID))
h.error(404, "User " + userID + " not found!");
}
if(!members.includes(h.getUserId()))
members.push(h.getUserId());
const conv : BaseConversation = {
ownerID: h.getUserId(),
name: name == "false" ? "" : name,
following: h.postBool("follow"),
members: members,
}
const convID = await ConversationsHelper.Create(conv);
// Success
h.send({
conversationID: convID,
success: "The conversation was successfully created!"
})
}
/**
* Get the list of conversations of the user
*

View File

@ -48,6 +48,8 @@ export const Routes : Route[] = [
// Conversations controller
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
{path: "/conversations/getList", cb: (h) => ConversationsController.GetList(h)},
{path: "/conversations/getInfoOne", cb: (h) => ConversationsController.GetInfoSingle(h)},