diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index 8c69fde..c5a6185 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -63,5 +63,10 @@ pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult { /// Update the settings of a conversation pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult { + let conv_id = r.post_conv_id("conversationID")?; + let is_moderator = conversations_helper::is_user_moderator(r.user_id()?, conv_id)?; + + println!("conv id: {} / is moderator: {}", conv_id, is_moderator); + r.success("implement it") } \ No newline at end of file diff --git a/src/helpers/conversations_helper.rs b/src/helpers/conversations_helper.rs index 772b6e7..95ab8d9 100644 --- a/src/helpers/conversations_helper.rs +++ b/src/helpers/conversations_helper.rs @@ -107,6 +107,14 @@ pub fn does_user_belongs_to(user_id: UserID, conv_id: u64) -> ResultBoxError 0) } +/// Check out wheter a user is the moderator of a conversation or not +pub fn is_user_moderator(user_id: UserID, conv_id: u64) -> ResultBoxError { + Ok(database::QueryInfo::new(CONV_LIST_TABLE) + .cond_u64("id", conv_id) + .cond_user_id("user_id", user_id) + .exec_count()? > 0) +} + /// Turn a database entry into a ConversationInfo object fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError { let conv_id = row.get_u64("id")?;