Compare commits
1 Commits
9e1886b45a
...
1fbafc25df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fbafc25df |
@@ -1,5 +1,6 @@
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use sea_orm::*;
|
use sea_orm::*;
|
||||||
|
use sea_orm::sea_query::Expr;
|
||||||
|
|
||||||
use crate::entities::wanted_item::{
|
use crate::entities::wanted_item::{
|
||||||
self, ActiveModel, Entity as WantedItems, ItemType, Model as WantedItem, WantedStatus,
|
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?;
|
WantedItems::delete_by_id(id).exec(db).await?;
|
||||||
Ok(())
|
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