Make recent get more better

This commit is contained in:
2024-06-13 08:53:45 +02:00
parent 057377186a
commit b96afa49a2
2 changed files with 4 additions and 5 deletions

View File

@@ -29,14 +29,13 @@ from food
order by date desc order by date desc
`) `)
}, },
async GetAllForDate(date: Date) { async GetRecent() {
return await db.select<Food[]>(` return await db.select<Food[]>(`
select ${columns.join(', ')} select ${columns.join(', ')}
from foodView from foodView
where strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', '2024-06-12') where date > datetime('now', "-48 hours")
or strftime('%Y-%m-%d', date) = strftime('%Y-%m-%d', date('2024-06-12', '-1 day'))
order by date DESC; order by date DESC;
`, [date]) `)
}, },
async Create(food: Food): Promise<[Food, Err]> { async Create(food: Food): Promise<[Food, Err]> {
if (!food.food) return [food, 'food.food is required'] if (!food.food) return [food, 'food.food is required']

View File

@@ -3,7 +3,7 @@ import { type Food, FoodService } from '$lib/database/food'
async function createStore(): Promise<Writable<Food[]>> { async function createStore(): Promise<Writable<Food[]>> {
const foods = await FoodService.GetAllForDate(new Date()) const foods = await FoodService.GetRecent()
const { subscribe, update, set } = writable(foods) const { subscribe, update, set } = writable(foods)
return { return {
subscribe, subscribe,