Fixing formula in enrichment calls, it did not retrieve the correct linked table for output processing, grouping rows for enrichment phase with their correct tables.

This commit is contained in:
mike12345567 2021-09-30 17:54:54 +01:00
parent 4ecc92de3b
commit 5bafd1c01b
2 changed files with 43 additions and 779 deletions

View File

@ -403,16 +403,32 @@ exports.fetchEnrichedRow = async ctx => {
rowId, rowId,
}) })
// look up the actual rows based on the ids // look up the actual rows based on the ids
const response = await db.allDocs({ let response = (
await db.allDocs({
include_docs: true, include_docs: true,
keys: linkVals.map(linkVal => linkVal.id), keys: linkVals.map(linkVal => linkVal.id),
}) })
).rows.map(row => row.doc)
// group responses by table
let groups = {},
tables = {}
for (let row of response) {
const linkedTableId = row.tableId
if (groups[linkedTableId] == null) {
groups[linkedTableId] = [row]
tables[linkedTableId] = await db.get(linkedTableId)
} else {
groups[linkedTableId].push(row)
}
}
let linkedRows = []
for (let [tableId, rows] of Object.entries(groups)) {
// need to include the IDs in these rows for any links they may have // need to include the IDs in these rows for any links they may have
let linkedRows = await outputProcessing( linkedRows = linkedRows.concat(
ctx, await outputProcessing(ctx, tables[tableId], rows)
table,
response.rows.map(row => row.doc)
) )
}
// insert the link rows in the correct place throughout the main row // insert the link rows in the correct place throughout the main row
for (let fieldName of Object.keys(table.schema)) { for (let fieldName of Object.keys(table.schema)) {
let field = table.schema[fieldName] let field = table.schema[fieldName]

File diff suppressed because it is too large Load Diff