27 lines
608 B
TypeScript
27 lines
608 B
TypeScript
import { type Writable, writable } from 'svelte/store'
|
|
import { type AggregatedWeight, WeightService } from '$lib/database/weight'
|
|
import { FoodService } from '$lib/database/food'
|
|
|
|
|
|
async function createStore(): Promise<Writable<AggregatedWeight[]>> {
|
|
let [rows, err] = await WeightService.GetDaily()
|
|
if (err) {
|
|
rows = []
|
|
console.error(err)
|
|
}
|
|
|
|
const { subscribe, update, set } = writable(rows)
|
|
return {
|
|
subscribe,
|
|
update,
|
|
set,
|
|
// @ts-ignore
|
|
refresh: async () => {
|
|
const rows = await WeightService.GetDaily()
|
|
set(rows[0])
|
|
}
|
|
}
|
|
}
|
|
|
|
export const dailyWeightStore = await createStore()
|