import getUri from '../lib/ids'; import { getFamily, put } from './lib'; import { putNewTrk } from './trk'; const emptyTrkseg: Trkseg = { trkpt: undefined, extensions: undefined, }; export const putNewTrkseg = async (id?: IdTrk | IdGpx | IdTrkseg) => { let finalId = { ...id }; if (!('trkseg' in finalId)) { const trkId = await putNewTrk(id); finalId = { ...trkId, trkseg: 0 }; } const uri = getUri('trkseg', finalId); await put( uri, 'trkseg', (trkseg) => { return trkseg; }, emptyTrkseg ); return finalId as IdTrkseg; }; export const getTrkseg = async (params: any) => { const { id } = params; const docs = await getFamily(id, { include_docs: true }); console.log(`getTrkseg, uri: ${id} docs: ${JSON.stringify(docs)}`); return docs.rows; };