Fix issue with food creation
This commit is contained in:
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user