dyomedea/src/db/wpt.ts

65 lines
1.2 KiB
TypeScript
Raw Normal View History

import getUri from '../lib/ids';
import { putNewGpx } from './gpx';
2022-11-28 10:52:50 +00:00
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;
};
2022-11-28 10:52:50 +00:00
2022-12-06 20:27:25 +00:00
export const putWpt = async (params: any) => {
console.log({ caller: 'putWpt', params });
const { id, wpt } = params;
await put(
id,
'wpt',
(_) => {
return wpt;
},
wpt
);
return id;
};
2022-11-28 10:52:50 +00:00
export const getWpt = async (params: any) => {
const { id } = params;
const doc = await get(id);
return doc.doc;
2022-12-06 20:27:25 +00:00
};