- Add root Dockerfile: node build → copy dist into Go embed path → distroless binary - Update docker-compose: one service (api on :9050), DB renamed ralph→pamietnik - Remove references to RALPH/reisejournal across all docs and configs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
export interface DaySummary {
|
|
date: string
|
|
count: number
|
|
first_ts?: string
|
|
last_ts?: string
|
|
}
|
|
|
|
export interface Trackpoint {
|
|
event_id: string
|
|
device_id: string
|
|
trip_id: string
|
|
timestamp: string
|
|
lat: number
|
|
lon: number
|
|
source: 'gps' | 'manual'
|
|
note?: string
|
|
}
|
|
|
|
export interface Stop {
|
|
stop_id: string
|
|
device_id: string
|
|
trip_id: string
|
|
start_ts: string
|
|
end_ts: string
|
|
center_lat: number
|
|
center_lon: number
|
|
duration_s: number
|
|
place_label?: string
|
|
}
|
|
|
|
export interface Suggestion {
|
|
suggestion_id: string
|
|
stop_id: string
|
|
type: 'highlight' | 'name_place' | 'add_note'
|
|
title: string
|
|
text: string
|
|
created_at: string
|
|
dismissed_at?: string
|
|
}
|
|
|
|
async function get<T>(path: string): Promise<T> {
|
|
const res = await fetch(path, { credentials: 'include' })
|
|
if (res.status === 401) {
|
|
window.location.href = '/login'
|
|
throw new Error('unauthenticated')
|
|
}
|
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
|
|
return res.json() as Promise<T>
|
|
}
|
|
|
|
export const api = {
|
|
getDays(from?: string, to?: string): Promise<DaySummary[]> {
|
|
const now = new Date()
|
|
const defaultTo = now.toISOString().slice(0, 10)
|
|
const past = new Date(now)
|
|
past.setDate(past.getDate() - 90)
|
|
const defaultFrom = past.toISOString().slice(0, 10)
|
|
const params = new URLSearchParams({
|
|
from: from ?? defaultFrom,
|
|
to: to ?? defaultTo,
|
|
})
|
|
return get<DaySummary[]>(`/v1/days?${params}`)
|
|
},
|
|
getTrackpoints(date: string): Promise<Trackpoint[]> {
|
|
return get<Trackpoint[]>(`/v1/trackpoints?date=${date}`)
|
|
},
|
|
getStops(date: string): Promise<Stop[]> {
|
|
return get<Stop[]>(`/v1/stops?date=${date}`)
|
|
},
|
|
getSuggestions(date: string): Promise<Suggestion[]> {
|
|
return get<Suggestion[]>(`/v1/suggestions?date=${date}`)
|
|
},
|
|
}
|