import getUri from '../lib/ids'; import { putNewGpx } from './gpx'; import { get, put } from './lib'; export const emptyWpt: Wpt = { $: { lat: 0, lon: 0 }, ele: undefined, time: undefined, magvar: undefined, geoidheight: undefined, name: undefined, cmt: undefined, desc: undefined, src: undefined, link: undefined, sym: undefined, type: undefined, fix: undefined, sat: undefined, hdop: undefined, vdop: undefined, pdop: undefined, ageofdgpsdata: undefined, dgpsid: undefined, extensions: undefined, }; export const putNewWpt = async (id?: IdGpx | IdWpt) => { let finalId = { ...id }; if (!('wpt' in finalId)) { const gpxId = await putNewGpx(id); finalId = { ...gpxId, wpt: 0 }; } const uri = getUri('wpt', finalId); await put( uri, 'wpt', (wpt) => { return wpt; }, emptyWpt ); return finalId as IdWpt; }; export const putWpt = async (params: any) => { console.log({ caller: 'putWpt', params }); const { id, wpt } = params; await put( id, 'wpt', (_) => { return wpt; }, wpt ); return id; }; export const getWpt = async (params: any) => { const { id } = params; const doc = await get(id); return doc.doc; };