Adapting the address fetcher for rtes.

This commit is contained in:
vdv committed 2023-02-10 06:35:10 +01:00
1 parent 796147e4a9
commit 31669d8aac
8 files changed
+67 -44

No files matched your search

+1 -2
View File
@@ -74,7 +74,6 @@ export const getRteDocs: ({
}) => Promise<{ docs: any; rte: Rte }> = async (params) => {
const { id } = params;
const docs = await getFamily(id, { include_docs: true });
console.log({ caller: 'getRteDocs', id, docs });
let rte: Rte;
if (docs.rows.length === 1) {
rte = docs.rows[0].doc.doc;
@@ -91,7 +90,7 @@ export const getRteDocs: ({
caller: 'getRteDocs',
id,
docs,
nbRteptIn: docs.rows[0].doc.rtept?.length,
nbRteptIn: docs.rows[0].doc.doc.rtept?.length,
nbRteptTotal: rte?.rtept?.length,
});
return { docs, rte };
+5 -5
View File
@@ -69,7 +69,7 @@ describe('The rtept module with a real db', () => {
const rtePut = await putRte({ id: idRte, rte: rte0 });
expect(rtePut).toEqual(rte0);
const rtePutRtept = await putRtept({ idRte, index: 1, rtept });
const rtePutRtept = await putRtept({ id: idRte, index: 1, wpt: rtept });
const rteGetRtept = await getRte({ id: idRte });
expect(rteGetRtept).toEqual(rte1);
});
@@ -123,9 +123,9 @@ describe('The rtept module with a real db', () => {
await put(idRtept, 'rtept', () => rtept3, emptyWpt);
expect(await getRte({ id: idRte })).toEqual(rte1);
await putRtept({
idRte,
id: idRte,
index: 2,
rtept: rtept4,
wpt: rtept4,
});
expect((await getFamily(idRte)).rows.length).toEqual(2);
expect(await getRte({ id: idRte })).toEqual(rte2);
@@ -179,9 +179,9 @@ describe('The rtept module with a real db', () => {
const rtePut = await putRte({ id: idRte, rte: rte0 });
await put(idRtept, 'rtept', () => rtept3, emptyWpt);
await putRtept({
idRte,
id: idRte,
index: -1,
rtept: rtept4,
wpt: rtept4,
});
expect(await getRte({ id: idRte })).toEqual(rte2);
expect((await get(idRtept)).doc).toEqual(rtept4);
+6 -6
View File
@@ -26,8 +26,8 @@ export const emptyRtept: Wpt = {
};
export const putRtept = async (params: any) => {
const { idRte, index, rtept } = params;
const { docs } = await getRteDocs({ id: idRte });
const { id, index, wpt } = params;
const { docs } = await getRteDocs({ id: id });
const rte = docs.rows[0].doc.doc;
const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0;
const nbRteptOutRte = docs.rows.length - 1;
@@ -41,11 +41,11 @@ export const putRtept = async (params: any) => {
// positiveIndex,
// });
if (positiveIndex < nbRteptInRte) {
rte.rtept[positiveIndex] = rtept;
await putRte({ id: idRte, rte });
rte.rtept[positiveIndex] = wpt;
await putRte({ id, rte });
} else {
const reptId = docs.rows[1 + positiveIndex - nbRteptInRte].doc._id;
await put(reptId, 'rtept', () => rtept, emptyRtept);
await put(reptId, 'rtept', () => wpt, emptyRtept);
}
return rtept;
return wpt;
};