mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
Clean inventory data for missing items on save
This commit is contained in:
parent
7549decc71
commit
55cfb013a8
@ -42,6 +42,16 @@
|
||||
},
|
||||
"query": "with latest_dates as (\n select user_id, max(date(plan_date)) as plan_date from plan_recipes\n where user_id = ?\n group by user_id\n)\n\nselect\n extra_items.name,\n extra_items.amt\nfrom latest_dates\ninner join extra_items on\n latest_dates.user_id = extra_items.user_id\n and latest_dates.plan_date = extra_items.plan_date"
|
||||
},
|
||||
"10e1c111a16d647a106a3147f4e61e34b0176860ca99cb62cb43dc72550ad990": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
}
|
||||
},
|
||||
"query": "delete from modified_amts where user_id = ? and plan_date = ?"
|
||||
},
|
||||
"160a9dfccf2e91a37d81f75eba21ec73105a7453c4f1fe76a430d04e525bc6cd": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
@ -126,6 +136,16 @@
|
||||
},
|
||||
"query": "insert into modified_amts(user_id, name, form, measure_type, amt, plan_date)\n values (?, ?, ?, ?, ?, ?) on conflict (user_id, name, form, measure_type, plan_date) do update set amt=excluded.amt"
|
||||
},
|
||||
"23beb05e40cf011170182d4e98cdf1faa3d8df6e5956e471245e666f32e56962": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
}
|
||||
},
|
||||
"query": "delete from filtered_ingredients where user_id = ? and plan_date = ?"
|
||||
},
|
||||
"2582522f8ca9f12eccc70a3b339d9030aee0f52e62d6674cfd3862de2a68a177": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
@ -364,6 +384,16 @@
|
||||
},
|
||||
"query": "insert into modified_amts(user_id, name, form, measure_type, amt, plan_date)\n values (?, ?, ?, ?, ?, date()) on conflict (user_id, name, form, measure_type, plan_date) do update set amt=excluded.amt"
|
||||
},
|
||||
"6f11d90875a6230766a5f9bd1d67665dc4d00c13d7e81b0d18d60baa67987da9": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
}
|
||||
},
|
||||
"query": "delete from extra_items where user_id = ? and plan_date = ?"
|
||||
},
|
||||
"7578157607967a6a4c60f12408c5d9900d15b429a49681a4cae4e02d31c524ec": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
|
@ -754,6 +754,7 @@ impl APIStore for SqliteStore {
|
||||
Ok((filtered_ingredients, modified_amts, extra_items))
|
||||
}
|
||||
|
||||
// TODO(jwall): Deprecated
|
||||
async fn fetch_latest_inventory_data<S: AsRef<str> + Send>(
|
||||
&self,
|
||||
user_id: S,
|
||||
@ -844,6 +845,13 @@ impl APIStore for SqliteStore {
|
||||
let user_id = user_id.as_ref();
|
||||
let mut transaction = self.pool.as_ref().begin().await?;
|
||||
// store the filtered_ingredients
|
||||
sqlx::query!(
|
||||
"delete from filtered_ingredients where user_id = ? and plan_date = ?",
|
||||
user_id,
|
||||
date
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
for key in filtered_ingredients {
|
||||
let name = key.name();
|
||||
let form = key.form();
|
||||
@ -859,6 +867,13 @@ impl APIStore for SqliteStore {
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
sqlx::query!(
|
||||
"delete from modified_amts where user_id = ? and plan_date = ?",
|
||||
user_id,
|
||||
date
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
// store the modified amts
|
||||
for (key, amt) in modified_amts {
|
||||
let name = key.name();
|
||||
@ -877,6 +892,13 @@ impl APIStore for SqliteStore {
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
}
|
||||
sqlx::query!(
|
||||
"delete from extra_items where user_id = ? and plan_date = ?",
|
||||
user_id,
|
||||
date
|
||||
)
|
||||
.execute(&mut transaction)
|
||||
.await?;
|
||||
// Store the extra items
|
||||
for (name, amt) in extra_items {
|
||||
sqlx::query_file!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user