Fix bug where clearing ticks on one day would clear all ticks for the track on all days
This commit is contained in:
parent
9b876511d9
commit
bfe0537750
4 changed files with 40 additions and 8 deletions
|
|
@ -87,6 +87,7 @@ pub(crate) fn start_server(db: DatabaseConnection) -> Rocket<Build> {
|
|||
ticked,
|
||||
ticked_on_date,
|
||||
clear_all_ticks,
|
||||
clear_all_ticks_on_day,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
|
|
|
|||
|
|
@ -158,3 +158,28 @@ pub(super) async fn clear_all_ticks(
|
|||
}
|
||||
Ok(Right(Json(ticks)))
|
||||
}
|
||||
|
||||
#[delete("/<id>/all-ticks?<year>&<month>&<day>")]
|
||||
pub(super) async fn clear_all_ticks_on_day(
|
||||
db: &State<DatabaseConnection>,
|
||||
tx: &State<Sender<Update>>,
|
||||
id: i32,
|
||||
year: i32,
|
||||
month: u32,
|
||||
day: u32,
|
||||
) -> ApiResult<Json<Vec<ticks::Model>>> {
|
||||
let db = db as &DatabaseConnection;
|
||||
let ticks = Ticks::find()
|
||||
.filter(ticks::Column::TrackId.eq(id))
|
||||
.filter(ticks::Column::Year.eq(year))
|
||||
.filter(ticks::Column::Month.eq(month))
|
||||
.filter(ticks::Column::Day.eq(day))
|
||||
.all(db)
|
||||
.await
|
||||
.map_err(Error::from)?;
|
||||
for tick in ticks.clone() {
|
||||
tick.clone().delete(db).await.map_err(Error::from)?;
|
||||
Update::tick_cancelled(tick).send(&tx)?;
|
||||
}
|
||||
Ok(Json(ticks))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue