Merge pull request #11919 from Budibase/BUDI-7403/google_integration
Fix column type on Google integration
This commit is contained in:
commit
4d445aae35
|
@ -269,13 +269,25 @@ function isEditableColumn(column: FieldSchema) {
|
||||||
return !(isExternalAutoColumn || isFormula)
|
return !(isExternalAutoColumn || isFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExternalRequest {
|
export type ExternalRequestReturnType<T> = T extends Operation.READ
|
||||||
private operation: Operation
|
?
|
||||||
private tableId: string
|
| Row[]
|
||||||
|
| {
|
||||||
|
row: Row
|
||||||
|
table: Table
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
row: Row
|
||||||
|
table: Table
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ExternalRequest<T extends Operation> {
|
||||||
|
private readonly operation: T
|
||||||
|
private readonly tableId: string
|
||||||
private datasource?: Datasource
|
private datasource?: Datasource
|
||||||
private tables: { [key: string]: Table } = {}
|
private tables: { [key: string]: Table } = {}
|
||||||
|
|
||||||
constructor(operation: Operation, tableId: string, datasource?: Datasource) {
|
constructor(operation: T, tableId: string, datasource?: Datasource) {
|
||||||
this.operation = operation
|
this.operation = operation
|
||||||
this.tableId = tableId
|
this.tableId = tableId
|
||||||
this.datasource = datasource
|
this.datasource = datasource
|
||||||
|
@ -739,7 +751,7 @@ export class ExternalRequest {
|
||||||
return fields
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(config: RunConfig) {
|
async run(config: RunConfig): Promise<ExternalRequestReturnType<T>> {
|
||||||
const { operation, tableId } = this
|
const { operation, tableId } = this
|
||||||
let { datasourceId, tableName } = breakExternalTableId(tableId)
|
let { datasourceId, tableName } = breakExternalTableId(tableId)
|
||||||
if (!tableName) {
|
if (!tableName) {
|
||||||
|
@ -830,8 +842,11 @@ export class ExternalRequest {
|
||||||
}
|
}
|
||||||
const output = this.outputProcessing(response, table, relationships)
|
const output = this.outputProcessing(response, table, relationships)
|
||||||
// if reading it'll just be an array of rows, return whole thing
|
// if reading it'll just be an array of rows, return whole thing
|
||||||
return operation === Operation.READ && Array.isArray(response)
|
const result = (
|
||||||
? output
|
operation === Operation.READ && Array.isArray(response)
|
||||||
: { row: output[0], table }
|
? output
|
||||||
|
: { row: output[0], table }
|
||||||
|
) as ExternalRequestReturnType<T>
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import { FieldTypes, NoEmptyFilterStrings } from "../../../constants"
|
import { FieldTypes } from "../../../constants"
|
||||||
import {
|
import {
|
||||||
breakExternalTableId,
|
breakExternalTableId,
|
||||||
breakRowIdField,
|
breakRowIdField,
|
||||||
} from "../../../integrations/utils"
|
} from "../../../integrations/utils"
|
||||||
import { ExternalRequest, RunConfig } from "./ExternalRequest"
|
import {
|
||||||
|
ExternalRequest,
|
||||||
|
ExternalRequestReturnType,
|
||||||
|
RunConfig,
|
||||||
|
} from "./ExternalRequest"
|
||||||
import {
|
import {
|
||||||
Datasource,
|
Datasource,
|
||||||
IncludeRelationship,
|
IncludeRelationship,
|
||||||
|
@ -24,11 +28,11 @@ import {
|
||||||
} from "../../../utilities/rowProcessor"
|
} from "../../../utilities/rowProcessor"
|
||||||
import { cloneDeep, isEqual } from "lodash"
|
import { cloneDeep, isEqual } from "lodash"
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest<T extends Operation>(
|
||||||
operation: Operation,
|
operation: T,
|
||||||
tableId: string,
|
tableId: string,
|
||||||
opts?: RunConfig
|
opts?: RunConfig
|
||||||
) {
|
): Promise<ExternalRequestReturnType<T>> {
|
||||||
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
|
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
|
||||||
if (opts && opts.filters) {
|
if (opts && opts.filters) {
|
||||||
opts.filters = sdk.rows.removeEmptyFilters(opts.filters)
|
opts.filters = sdk.rows.removeEmptyFilters(opts.filters)
|
||||||
|
@ -37,7 +41,7 @@ export async function handleRequest(
|
||||||
!dataFilters.hasFilters(opts?.filters) &&
|
!dataFilters.hasFilters(opts?.filters) &&
|
||||||
opts?.filters?.onEmptyFilter === EmptyFilterOption.RETURN_NONE
|
opts?.filters?.onEmptyFilter === EmptyFilterOption.RETURN_NONE
|
||||||
) {
|
) {
|
||||||
return []
|
return [] as any
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ExternalRequest(operation, tableId, opts?.datasource).run(
|
return new ExternalRequest(operation, tableId, opts?.datasource).run(
|
||||||
|
@ -68,12 +72,10 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
||||||
id: breakRowIdField(_id),
|
id: breakRowIdField(_id),
|
||||||
row: dataToUpdate,
|
row: dataToUpdate,
|
||||||
})
|
})
|
||||||
const row = await sdk.rows.external.getRow(tableId, _id, {
|
const row = await outputProcessing(table, response.row)
|
||||||
relationships: true,
|
|
||||||
})
|
|
||||||
return {
|
return {
|
||||||
...response,
|
...response,
|
||||||
row: await outputProcessing(table, row),
|
row,
|
||||||
table,
|
table,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {
|
import {
|
||||||
ConnectionInfo,
|
ConnectionInfo,
|
||||||
Datasource,
|
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
DatasourceFieldType,
|
DatasourceFieldType,
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
|
@ -23,7 +22,6 @@ import fetch from "node-fetch"
|
||||||
import { cache, configs, context, HTTPError } from "@budibase/backend-core"
|
import { cache, configs, context, HTTPError } from "@budibase/backend-core"
|
||||||
import { dataFilters, utils } from "@budibase/shared-core"
|
import { dataFilters, utils } from "@budibase/shared-core"
|
||||||
import { GOOGLE_SHEETS_PRIMARY_KEY } from "../constants"
|
import { GOOGLE_SHEETS_PRIMARY_KEY } from "../constants"
|
||||||
import sdk from "../sdk"
|
|
||||||
|
|
||||||
interface GoogleSheetsConfig {
|
interface GoogleSheetsConfig {
|
||||||
spreadsheetId: string
|
spreadsheetId: string
|
||||||
|
@ -56,6 +54,7 @@ const ALLOWED_TYPES = [
|
||||||
FieldType.OPTIONS,
|
FieldType.OPTIONS,
|
||||||
FieldType.BOOLEAN,
|
FieldType.BOOLEAN,
|
||||||
FieldType.BARCODEQR,
|
FieldType.BARCODEQR,
|
||||||
|
FieldType.BB_REFERENCE,
|
||||||
]
|
]
|
||||||
|
|
||||||
const SCHEMA: Integration = {
|
const SCHEMA: Integration = {
|
||||||
|
@ -213,7 +212,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
await setupCreationAuth(this.config)
|
await setupCreationAuth(this.config)
|
||||||
|
|
||||||
// Initialise oAuth client
|
// Initialise oAuth client
|
||||||
let googleConfig = await configs.getGoogleDatasourceConfig()
|
const googleConfig = await configs.getGoogleDatasourceConfig()
|
||||||
if (!googleConfig) {
|
if (!googleConfig) {
|
||||||
throw new HTTPError("Google config not found", 400)
|
throw new HTTPError("Google config not found", 400)
|
||||||
}
|
}
|
||||||
|
@ -552,6 +551,10 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
typeof query.row === "string" ? JSON.parse(query.row) : query.row
|
typeof query.row === "string" ? JSON.parse(query.row) : query.row
|
||||||
for (let key in updateValues) {
|
for (let key in updateValues) {
|
||||||
row[key] = updateValues[key]
|
row[key] = updateValues[key]
|
||||||
|
|
||||||
|
if (row[key] === null) {
|
||||||
|
row[key] = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await row.save()
|
await row.save()
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue