Fix issue with food creation

This commit is contained in:
2024-06-12 09:45:41 +02:00
parent b4d8543a5f
commit 5a791dcb3d
2 changed files with 11 additions and 6 deletions

View File

@@ -31,12 +31,12 @@ order by date DESC;
`, [date])
},
// TODO: Rework this to use Err in Go style
async Create(food: Food): Promise<[Food, Err]> {
if (!food.food) return [food, 'food.food is required']
if (!food.amount) throw [food, 'food.amount is required']
async Create(food: Food): Promise<[Food[], Err]> {
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])
const row = await db.select<Food>(`select ${columns.join(', ')} from food where rowid = $1`, [res.lastInsertId])
const row = await db.select<Food[]>(`select ${columns.join(', ')} from food where rowid = $1`, [res.lastInsertId])
return [row, null]
}