Fixing googlesheets filtering by _id - there was an issue with the response API giving _rowNumber rather than the expected primary key of rowNumber, need to update the filters accordingly.

This commit is contained in:
mike12345567 2023-06-02 18:25:35 +01:00
parent 213315e14f
commit e7649374d2
1 changed files with 20 additions and 1 deletions

View File

@ -472,6 +472,20 @@ class GoogleSheetsIntegration implements DatasourcePlus {
} else { } else {
rows = await sheet.getRows() rows = await sheet.getRows()
} }
// this is a special case - need to handle the _id, it doesn't exist
// we cannot edit the returned structure from google, it does not have
// setter functions and is immutable, easier to update the filters
// to look for the _rowNumber property rather than rowNumber
if (query.filters?.equal) {
const idFilterKeys = Object.keys(query.filters.equal).filter(filter =>
filter.includes(GOOGLE_SHEETS_PRIMARY_KEY)
)
for (let idFilterKey of idFilterKeys) {
const id = query.filters.equal[idFilterKey]
delete query.filters.equal[idFilterKey]
query.filters.equal[`_${GOOGLE_SHEETS_PRIMARY_KEY}`] = id
}
}
const filtered = dataFilters.runLuceneQuery(rows, query.filters) const filtered = dataFilters.runLuceneQuery(rows, query.filters)
const headerValues = sheet.headerValues const headerValues = sheet.headerValues
let response = [] let response = []
@ -535,7 +549,12 @@ class GoogleSheetsIntegration implements DatasourcePlus {
const row = rows[query.rowIndex] const row = rows[query.rowIndex]
if (row) { if (row) {
await row.delete() await row.delete()
return [{ deleted: query.rowIndex, [GOOGLE_SHEETS_PRIMARY_KEY]: query.rowIndex }] return [
{
deleted: query.rowIndex,
[GOOGLE_SHEETS_PRIMARY_KEY]: query.rowIndex,
},
]
} else { } else {
throw new Error("Row does not exist.") throw new Error("Row does not exist.")
} }