2023-02-08 21:39:04 +00:00
|
|
|
import { getRteDocs, putRte } from './rte';
|
|
|
|
import getUri from '../lib/ids';
|
|
|
|
import { put } from './lib';
|
2022-11-26 18:36:55 +00:00
|
|
|
|
|
|
|
export const emptyRtept: 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,
|
|
|
|
};
|
2023-02-08 21:39:04 +00:00
|
|
|
|
|
|
|
export const putRtept = async (params: any) => {
|
2023-02-10 05:35:10 +00:00
|
|
|
const { id, index, wpt } = params;
|
|
|
|
const { docs } = await getRteDocs({ id: id });
|
2023-02-09 20:07:09 +00:00
|
|
|
const rte = docs.rows[0].doc.doc;
|
2023-02-08 21:39:04 +00:00
|
|
|
const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0;
|
|
|
|
const nbRteptOutRte = docs.rows.length - 1;
|
|
|
|
const nbRtept = nbRteptInRte + nbRteptOutRte;
|
2023-02-09 20:11:17 +00:00
|
|
|
const positiveIndex = index >= 0 ? index : nbRtept + index;
|
2023-02-09 20:07:09 +00:00
|
|
|
// console.log({
|
|
|
|
// caller: 'putRtept',
|
|
|
|
// nbRteptInRte,
|
|
|
|
// nbRteptOutRte,
|
|
|
|
// nbRtept,
|
|
|
|
// positiveIndex,
|
|
|
|
// });
|
2023-02-08 21:39:04 +00:00
|
|
|
if (positiveIndex < nbRteptInRte) {
|
2023-02-10 05:35:10 +00:00
|
|
|
rte.rtept[positiveIndex] = wpt;
|
|
|
|
await putRte({ id, rte });
|
2023-02-08 21:39:04 +00:00
|
|
|
} else {
|
2023-02-09 20:07:09 +00:00
|
|
|
const reptId = docs.rows[1 + positiveIndex - nbRteptInRte].doc._id;
|
2023-02-10 05:35:10 +00:00
|
|
|
await put(reptId, 'rtept', () => wpt, emptyRtept);
|
2023-02-08 21:39:04 +00:00
|
|
|
}
|
2023-02-10 05:35:10 +00:00
|
|
|
return wpt;
|
2023-02-08 21:39:04 +00:00
|
|
|
};
|