Compare commits

..

No commits in common. "75d9bab34d3a48f0aee340c76044e0c3b827740c" and "9b876511d967f8363d2f6e468506cafe5975bbb5" have entirely different histories.

4 changed files with 8 additions and 40 deletions

View file

@ -15,7 +15,7 @@ const className = computed(() => isSet.value ? "button is-rounded is-info" : "bu
async function toggle() {
if (isSet.value) {
await state.taskMarkedIncomplete(props.track, props.date)
await state.taskMarkedIncomplete(props.track)
} else
await state.taskCompleted(props.track, props.date)
}

View file

@ -8,15 +8,6 @@ enum State {
Fetched,
}
function dateQuery(date: Date): URLSearchParams {
let query = new URLSearchParams()
query.set("year", date.getUTCFullYear().toString())
query.set("month", (date.getUTCMonth() + 1).toString())
// good thing I still had this ^^^^^^^^^^^^^^ in mind when I wrote this 😬
query.set("day", date.getUTCDate().toString())
return query
}
export const state = reactive({
tracks: new Array<Track>,
state: State.Unfetched,
@ -71,7 +62,11 @@ export const state = reactive({
this.state = State.Fetched
},
async taskCompleted(track: Track, date: Date): Promise<Tick> {
const query = dateQuery(date)
let query = new URLSearchParams()
query.append("year", date.getUTCFullYear().toString())
query.append("month", (date.getUTCMonth() + 1).toString())
// good thing I still had this ^^^^^^^^^^^^^^ in mind when I wrote this 😬
query.append("day", date.getUTCDate().toString())
const response: Response = await fetch(`/api/v1/tracks/${track.id}/ticked?${query.toString()}`, { method: "PATCH" })
const body = await response.text()
if (!response.ok) {
@ -80,9 +75,8 @@ export const state = reactive({
}
return JSON.parse(body)
},
async taskMarkedIncomplete(track: Track, date: Date) {
const query = dateQuery(date)
const { ok, status, statusText } = await fetch(`/api/v1/tracks/${track.id}/all-ticks?${query.toString()}`, { method: 'DELETE' })
async taskMarkedIncomplete(track: Track) {
const { ok, status, statusText } = await fetch(`/api/v1/tracks/${track.id}/all-ticks`, { method: 'DELETE' })
if (!ok)
error(`error deleting ticks for ${track.id}: ${statusText} (${status})`)
}

View file

@ -87,7 +87,6 @@ pub(crate) fn start_server(db: DatabaseConnection) -> Rocket<Build> {
ticked,
ticked_on_date,
clear_all_ticks,
clear_all_ticks_on_day,
],
)
.mount(

View file

@ -158,28 +158,3 @@ 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))
}