dyomedea/src/db/trk.ts

34 lines
655 B
TypeScript
Raw Normal View History

import getUri from '../lib/ids';
2022-11-08 13:16:23 +00:00
import { putNewGpx } from './gpx';
import { put } from './lib';
2022-11-08 21:02:06 +00:00
export const emptyTrk: Trk = {
2022-11-08 13:16:23 +00:00
name: undefined,
cmt: undefined,
desc: undefined,
src: undefined,
link: undefined,
number: 0,
2022-11-08 13:16:23 +00:00
type: undefined,
extensions: undefined,
trkseg: undefined,
};
2022-11-08 13:16:23 +00:00
export const putNewTrk = async (id?: IdTrk | IdGpx) => {
let finalId = { ...id };
if (!('trk' in finalId)) {
const gpxId = await putNewGpx(id);
finalId = { ...gpxId, trk: 0 };
2022-11-08 13:16:23 +00:00
}
const uri = getUri('trk', finalId);
2022-11-08 17:57:37 +00:00
await put(
2022-11-08 13:16:23 +00:00
uri,
'trk',
(trk) => {
return trk;
},
emptyTrk
);
2022-11-08 20:09:33 +00:00
return finalId as IdTrk;
2022-11-08 13:16:23 +00:00
};