This commit is contained in:
Eric van der Vlist 2023-02-13 15:59:41 +01:00
parent 6dfe98b655
commit 8d32fa253a
2 changed files with 66 additions and 44 deletions

View File

@ -26,10 +26,14 @@ const methods = {
const sendUpdate = async (params: any) => { const sendUpdate = async (params: any) => {
if (params) { if (params) {
console.log({ caller: 'ChangeHandler / sendUpdate', params }); console.log({ caller: 'ChangeHandler / sendUpdate', params });
const { method, _dispatchId, id, ...otherParams } = params; try {
const returnValue = await methods[<keyof typeof methods>method](params); const { method, _dispatchId, id, ...otherParams } = params;
if (returnValue) { const returnValue = await methods[<keyof typeof methods>method](params);
returnAgain(_dispatchId, returnValue); if (returnValue) {
returnAgain(_dispatchId, returnValue);
}
} catch (error) {
console.error({ caller: 'ChangeHandler / sendUpdate', params, error });
} }
} }
}; };

View File

@ -420,53 +420,71 @@ export const appendTrk = async (params: any) => {
export const putGpx = async (params: any) => { export const putGpx = async (params: any) => {
let { id, gpx } = params; let { id, gpx } = params;
if (id === 'new') { try {
const date = !!gpx.metadata.time ? new Date(gpx.metadata.time) : new Date(); if (id === 'new') {
id = getUri('gpx', { const date = !!gpx.metadata.time
gpx: intToGpxId(date.valueOf()), ? new Date(gpx.metadata.time)
}); : new Date();
} id = getUri('gpx', {
gpx: intToGpxId(date.valueOf()),
const previousShared = (await get(`${id}/4extensions`)).doc?.shared; });
console.log({ caller: 'putGpx', params, id, gpx, previousShared });
const extensions = gpx?.extensions;
gpx.extensions = undefined;
gpx.wpt = undefined;
gpx.trk = undefined;
gpx.rte = undefined;
await put(id, 'gpx', (doc) => gpx, gpx);
if (extensions !== undefined) {
try {
await put(
`${id}/4extensions`,
'extensions',
(doc) => extensions,
extensions
);
} catch (error) {
console.error({ caller: 'putGpx / extensions', error });
} }
}
if (previousShared !== extensions?.shared) { let previousShared;
const shared = extensions?.shared.split(/\s*,\s*/); try {
const family = (await getFamily(id, { include_docs: true })).rows.map( previousShared = (await get(`${id}/4extensions`)).doc?.shared;
(row: any) => { } catch (error) {}
return { ...row.doc, shared };
console.log({ caller: 'putGpx', params, id, gpx, previousShared });
const extensions = gpx?.extensions;
gpx.extensions = undefined;
gpx.wpt = undefined;
gpx.trk = undefined;
gpx.rte = undefined;
await put(id, 'gpx', (doc) => gpx, gpx);
if (extensions !== undefined) {
try {
await put(
`${id}/4extensions`,
'extensions',
(doc) => extensions,
extensions
);
} catch (error) {
console.error({
caller: 'putGpx / extensions',
error,
});
} }
); }
console.log({
caller: 'putGpx / updateShared', if (previousShared !== extensions?.shared) {
const shared = extensions?.shared.split(/\s*,\s*/);
const family = (await getFamily(id, { include_docs: true })).rows.map(
(row: any) => {
return { ...row.doc, shared };
}
);
console.log({
caller: 'putGpx / updateShared',
params,
id,
gpx,
previousShared,
family,
});
await db.bulkDocs(family);
}
} catch (error) {
console.error({
caller: 'putGpx',
params, params,
id, id,
gpx, gpx,
previousShared, error,
family,
}); });
await db.bulkDocs(family);
} }
return id; return id;