Add expire ban button to incidents command
This commit is contained in:
@@ -1570,6 +1570,43 @@ impl UserIncident {
|
||||
&& self.r#type == UserIncidentType::Ban
|
||||
}
|
||||
|
||||
pub async fn get_by_user_and_incident_id(
|
||||
user_id: u64,
|
||||
incident_id: u64,
|
||||
session: &Session,
|
||||
) -> Result<Option<Self>, DatabaseError> {
|
||||
let user_id = u64_to_i64(user_id);
|
||||
let incident_id = u64_to_i64(incident_id);
|
||||
|
||||
let result = session
|
||||
.query_unpaged(
|
||||
r#"
|
||||
SELECT
|
||||
user_id,
|
||||
incident_id,
|
||||
report_id,
|
||||
type,
|
||||
message,
|
||||
reason,
|
||||
created_by_id,
|
||||
created_at,
|
||||
expires_at,
|
||||
duration
|
||||
FROM
|
||||
payphone.user_incidents
|
||||
WHERE
|
||||
user_id = ? AND incident_id = ?;
|
||||
"#,
|
||||
(user_id, incident_id),
|
||||
)
|
||||
.await
|
||||
.map_err(DatabaseError::QueryError)?
|
||||
.into_rows_result()
|
||||
.map_err(|_| DatabaseError::ResultNotRows)?;
|
||||
|
||||
get_single_row_from_result(&result).await
|
||||
}
|
||||
|
||||
pub async fn get_for_user(user_id: u64, session: &Session) -> Result<Vec<Self>, DatabaseError> {
|
||||
let user_id = u64_to_i64(user_id);
|
||||
|
||||
@@ -1655,4 +1692,20 @@ impl UserIncident {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn expire_by_user_and_incident_id(
|
||||
user_id: u64,
|
||||
incident_id: u64,
|
||||
session: &Session,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let Some(mut incident) =
|
||||
Self::get_by_user_and_incident_id(user_id, incident_id, session).await?
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
incident.expires_at = Some(UtcDateTime::now());
|
||||
|
||||
incident.insert(session).await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user