turned on WAL on db, fix force update of passwords
This commit is contained in:
@@ -66,13 +66,19 @@ pub async fn add_user_to_conv(
|
||||
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "prepare failed".to_string())
|
||||
};
|
||||
|
||||
if !statement.exists(params![user_id, payload.conv_id])
|
||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Query failed".to_string())).unwrap()
|
||||
{
|
||||
// Early exit if not creator
|
||||
return ((StatusCode::FORBIDDEN, "Not the creator".to_string()));
|
||||
}
|
||||
match statement.exists(params![user_id, payload.conv_id]) {
|
||||
Ok(true) => {
|
||||
//user is creator
|
||||
}
|
||||
Ok(false) => {
|
||||
//user is not the creator
|
||||
return (StatusCode::FORBIDDEN, "Not the creato of the conversation".to_string())
|
||||
}
|
||||
Err(_) => {
|
||||
return(StatusCode::INTERNAL_SERVER_ERROR, "Query failed".to_string())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for target_id in &payload.users {
|
||||
let rows_inserted = match conn.execute(
|
||||
@@ -114,13 +120,19 @@ pub async fn send_message(
|
||||
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "prepare failed".to_string())
|
||||
};
|
||||
|
||||
if !statement.exists(params![user_id, payload.conv_id])
|
||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Query failed".to_string()))
|
||||
.unwrap()
|
||||
{
|
||||
// Early exit if not creator
|
||||
return ((StatusCode::FORBIDDEN, "Not part of the conversation".to_string()));
|
||||
match statement.exists(params![user_id, payload.conv_id]) {
|
||||
Ok(true) => {
|
||||
// user is part of the conversation — continue
|
||||
}
|
||||
Ok(false) => {
|
||||
// early exit: not part of the conversation
|
||||
return (StatusCode::FORBIDDEN, "Not part of the conversation".to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
// query failed
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, "Query failed".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
let result = conn.execute(
|
||||
"INSERT INTO message (sender_id, content, conversation_id) VALUES (?1, ?2, ?3)",
|
||||
@@ -209,11 +221,15 @@ pub async fn get_message(
|
||||
sent_at: row.get(3)?,
|
||||
})
|
||||
}
|
||||
).map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Query failed".to_string()))?
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Collect failed".to_string()))?;
|
||||
)
|
||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Query failed".to_string()))?
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Collect failed".to_string()))?;
|
||||
|
||||
Ok((StatusCode::OK, serde_json::to_string(&messages).unwrap()))
|
||||
let response = serde_json::to_string(&messages)
|
||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Serialisation failed"));
|
||||
|
||||
Ok((StatusCode::OK, response ))
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user