More updates related to the previous changes.

This commit is contained in:
vdv committed 2023-02-08 22:39:04 +01:00
1 parent 92ffe42ab9
commit e2ef46b612
5 files changed
+38 -9

No files matched your search

+7 -4
View File
@@ -56,8 +56,8 @@ const compactRteOrTrkseg = (params: any) => {
return { ...row.doc, doc: undefined, _deleted: true };
});
db.bulkDocs(compactedDocs);
console.log({ caller: 'compactRteOrTrkseg', params, compactedDocs });
}
console.log({ caller: 'compactRteOrTrkseg', params, compactedDocs });
});
};
@@ -67,10 +67,14 @@ export const compactRteOrTrksegDebounced = debounceByParam(
3600000 * (1 + Math.random())
);
const getRteDocs = async (params: any) => {
export const getRteDocs: ({
id,
}: {
id: string;
}) => Promise<{ docs: any; rte: Rte }> = async (params) => {
const { id } = params;
const docs = await getFamily(id, { include_docs: true });
// console.log({ caller: 'getRte', id, docs });
console.log({ caller: 'getRteDocs', id, docs });
let target: any[];
let rte: Rte | undefined = undefined;
docs.rows.every((row: any) => {
@@ -112,7 +116,6 @@ export const getRte = async (params: any) => {
export const putRte = async (params: any) => {
const { id, rte } = params;
rte.rtept = undefined;
await put(id, 'rte', (doc) => rte, rte);
return rte;
};
+22
View File
@@ -1,3 +1,6 @@
import { getRteDocs, putRte } from './rte';
import getUri from '../lib/ids';
import { put } from './lib';
export const emptyRtept: Wpt = {
$: { lat: 0, lon: 0 },
@@ -21,3 +24,22 @@ export const emptyRtept: Wpt = {
dgpsid: undefined,
extensions: undefined,
};
export const putRtept = async (params: any) => {
const { idRte, index, rtept } = params;
const { docs, rte } = await getRteDocs({ id: idRte });
const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0;
const nbRteptOutRte = docs.rows.length - 1;
const nbRtept = nbRteptInRte + nbRteptOutRte;
const positiveIndex = index >= 0 ? index : nbRtept - index;
if (positiveIndex < nbRteptInRte) {
rte.rtept[positiveIndex] = rtept;
await putRte({ id: idRte, rte });
} else {
let rteptIdObj = getUri('rtept', docs.rows[1].id);
rteptIdObj.rtept = rteptIdObj.rtept + positiveIndex - nbRteptInRte;
const rteptUri = getUri('rtept', rteptIdObj);
await put(rteptUri, 'rtept', () => rtept, emptyRtept);
}
return rte;
};