From 3932daa26360d6e03807381d0b8ffa2d0e704847 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 17 Apr 2023 20:56:53 +0200 Subject: Validate income date from body --- src/db/incomes.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/db') diff --git a/src/db/incomes.rs b/src/db/incomes.rs index f2eaf1c..2952d62 100644 --- a/src/db/incomes.rs +++ b/src/db/incomes.rs @@ -139,7 +139,7 @@ VALUES "#, ) .bind(i.user_id) - .bind(NaiveDate::from_ymd_opt(i.year, i.month, 1)?) + .bind(i.date) .bind(i.amount) .execute(pool) .await; @@ -156,8 +156,7 @@ VALUES pub async fn defined_at( pool: &SqlitePool, user_id: i64, - month: u32, - year: i32, + date: NaiveDate, ) -> Vec { let query = r#" SELECT @@ -172,7 +171,7 @@ WHERE let res = sqlx::query(&query) .bind(user_id) - .bind(NaiveDate::from_ymd(year, month, 1)) + .bind(date) .map(|row: SqliteRow| row.get("id")) .fetch_all(pool) .await; @@ -202,7 +201,7 @@ WHERE "#, ) .bind(i.user_id) - .bind(NaiveDate::from_ymd(i.year, i.month, 1)) + .bind(i.date) .bind(i.amount) .bind(id) .execute(pool) -- cgit v1.2.3