From 988d6d09364fbaa33320550e0bdc74e3f3ebf256 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 23 Nov 2019 19:31:48 +0100 Subject: [PATCH] Can check out whether a user belongs to a conversation or not --- src/helpers/ConversationsHelper.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index 65791b3..c3894cb 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -51,6 +51,22 @@ export class ConversationsHelper { } + /** + * Check out whether a user is the member of a conversation or not + * + * @param userID Target user ID + * @param convID Target conversation + */ + public static async DoesUsersBelongsTo(userID: number, convID: number) : Promise { + return await DatabaseHelper.Count({ + table: USERS_TABLE, + where: { + conv_id: convID, + user_id: userID + } + }) == 1; + } + /** * Get the list of members of a conversation *