From f07bf07c3f94fccc3c3f3fb086865b7bbabf2f77 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sat, 4 Mar 2023 15:13:27 +0100 Subject: [PATCH] Replacing shared by to --- src/db/gpx.ts | 34 +++++++++++++++++----------------- src/db/lib.ts | 8 ++++---- src/db/types.d.ts | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/db/gpx.ts b/src/db/gpx.ts index d214eae..a392a1b 100644 --- a/src/db/gpx.ts +++ b/src/db/gpx.ts @@ -80,7 +80,7 @@ const prune = ( }, extensions: any, docs: any[], - shared: string[] + to: string[] ) => { if (typeof object === 'object') { for (const key in object) { @@ -126,14 +126,14 @@ const prune = ( docs.push({ _id: getUri(key, subId), type: key, - shared, + to, origin: state().remoteUrl, doc: subObjects[index], }); - prune(subId, subObjects[index], previousIds, {}, docs, shared); + prune(subId, subObjects[index], previousIds, {}, docs, to); } object[key] = undefined; - } else prune(id, object[key], previousIds, extensions, docs, shared); + } else prune(id, object[key], previousIds, extensions, docs, to); } } }; @@ -187,7 +187,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => { }; convertTrkToRteWhenNeeded(gpx); let previousGpx: Gpx | null = null; - let shared: string[]; + let to: string[]; if (id === 'new') { const currentDateTime = new Date().toISOString(); const startTime = new Date(findStartTime(gpx, currentDateTime)); @@ -204,7 +204,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => { type: 'gpx', origin: state().remoteUrl, doc: gpx, - // a new GPX isn't shared... + // a new GPX isn't to... }, { _id: getUri('extensions', gpxId), @@ -216,8 +216,8 @@ export const pruneAndSaveImportedGpx = async (params: any) => { } else { gpxId = getUri('gpx', id); previousGpx = (await getGpx({ id })) ?? null; - if (previousGpx?.extensions?.shared) { - shared = previousGpx?.extensions?.shared.split(/\s*,\s*/); + if (previousGpx?.extensions?.to) { + to = previousGpx?.extensions?.to.split(/\s*,\s*/); } console.log({ caller: 'pruneAndSaveImportedGpx / previousGpx', @@ -249,7 +249,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => { const trkId = getUri('trk', trkUri); previousIds.trk = trkId.trk; } - prune(gpxId, gpx, previousIds, extensions, docs, shared); + prune(gpxId, gpx, previousIds, extensions, docs, to); console.log({ caller: 'pruneAndSaveImportedGpx / pruned', docs }); try { const result = await putAll(docs); @@ -430,12 +430,12 @@ export const putGpx = async (params: any) => { }); } - let previousShared; + let previousTo; try { - previousShared = (await get(`${id}/4extensions`)).doc?.shared; + previousTo = (await get(`${id}/4extensions`)).doc?.to; } catch (error) {} - console.log({ caller: 'putGpx', params, id, gpx, previousShared }); + console.log({ caller: 'putGpx', params, id, gpx, previousTo }); const extensions = gpx?.extensions; gpx.extensions = undefined; @@ -460,19 +460,19 @@ export const putGpx = async (params: any) => { } } - if (previousShared !== extensions?.shared) { - const shared = extensions?.shared.split(/\s*,\s*/); + if (previousTo !== extensions?.to) { + const to = extensions?.to.split(/\s*,\s*/); const family = (await getFamily(id, { include_docs: true })).rows.map( (row: any) => { - return { ...row.doc, shared }; + return { ...row.doc, to }; } ); console.log({ - caller: 'putGpx / updateShared', + caller: 'putGpx / updateTo', params, id, gpx, - previousShared, + previousTo, family, }); await db.bulkDocs(family); diff --git a/src/db/lib.ts b/src/db/lib.ts index f61d7ab..0a2ff51 100644 --- a/src/db/lib.ts +++ b/src/db/lib.ts @@ -21,20 +21,20 @@ export const put = async ( current = await targetDb.get(_id); } catch { const parentId = getParentId(_id); - let shared; + let to; try { const parent = await db.get(parentId); // console.log({ caller: 'put', parent }); - shared = parent.shared; + to = parent.to; } catch {} - current = { _rev: undefined, shared, doc: cloneDeep(defaultDoc) }; + current = { _rev: undefined, to, doc: cloneDeep(defaultDoc) }; } try { putDoc = { _id, _rev: current._rev, type, - shared: current.shared, + to: current.to, origin: current.origin ?? state().remoteUrl, doc: update(current.doc), }; diff --git a/src/db/types.d.ts b/src/db/types.d.ts index 7e47127..f0529f9 100644 --- a/src/db/types.d.ts +++ b/src/db/types.d.ts @@ -50,7 +50,7 @@ interface Extensions { 'dyo:useragent'?: string; 'dyo:minZoom'?: number; address?: any; - shared?: string; + to?: string; } interface Trk {