Added proper "owned"status move
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use chrono::Utc;
|
||||
use sea_orm::*;
|
||||
use sea_orm::sea_query::Expr;
|
||||
|
||||
use crate::entities::wanted_item::{
|
||||
self, ActiveModel, Entity as WantedItems, ItemType, Model as WantedItem, WantedStatus,
|
||||
@@ -65,3 +66,15 @@ pub async fn remove(db: &DatabaseConnection, id: i32) -> DbResult<()> {
|
||||
WantedItems::delete_by_id(id).exec(db).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Promote all Downloaded items to Owned status. Returns the count updated.
|
||||
pub async fn promote_downloaded_to_owned(db: &DatabaseConnection) -> DbResult<u64> {
|
||||
let now = Utc::now().naive_utc();
|
||||
let result = WantedItems::update_many()
|
||||
.col_expr(wanted_item::Column::Status, Expr::value("owned"))
|
||||
.col_expr(wanted_item::Column::UpdatedAt, Expr::value(now))
|
||||
.filter(wanted_item::Column::Status.eq(WantedStatus::Downloaded))
|
||||
.exec(db)
|
||||
.await?;
|
||||
Ok(result.rows_affected)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user