Fix not inserting per100s

This commit is contained in:
2024-06-12 18:37:48 +02:00
parent 7f033b9358
commit c83f51a00b
2 changed files with 8 additions and 2 deletions

View File

@@ -28,8 +28,10 @@
if (event.key == 'Enter') {
event.preventDefault()
item.food = name
item.amount = parseInt(amount)
item.description = description
item.amount = parseInt(amount)
item.per100 = parseInt(per100)
const [dbFood, err]: [Food, Err] = await FoodService.Create(item)
name = ''
amount = ''

View File

@@ -42,7 +42,11 @@ order by date DESC;
if (!food.food) return [food, 'food.food is required']
if (!food.amount) throw [food, 'food.amount is required']
const res = await db.execute(`insert into food (food, description, amount) values ($1, $2, $3)`, [food.food, food.description, food.amount])
let res
if (!!food.per100)
res = await db.execute(`insert into food (food, description, amount, per100) values ($1, $2, $3, $4)`, [food.food, food.description, food.amount, food.per100])
else
res = await db.execute(`insert into food (food, description, amount) values ($1, $2, $3)`, [food.food, food.description, food.amount])
const rows = await db.select<Food[]>(`select ${columns.join(', ')} from foodView where rowid = $1`, [res.lastInsertId])
if (!rows) return [food, 'no data found']