Extract external getrow to sdk

This commit is contained in:
Adria Navarro 2023-07-26 16:03:14 +02:00
parent 292bb2ad62
commit 2457bf1b37
3 changed files with 27 additions and 18 deletions

View File

@ -16,20 +16,6 @@ import {
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
async function getRow(
tableId: string,
rowId: string,
opts?: { relationships?: boolean }
) {
const response = (await handleRequest(Operation.READ, tableId, {
id: breakRowIdField(rowId),
includeSqlRelationships: opts?.relationships
? IncludeRelationship.INCLUDE
: IncludeRelationship.EXCLUDE,
})) as Row[]
return response ? response[0] : response
}
export async function handleRequest( export async function handleRequest(
operation: Operation, operation: Operation,
tableId: string, tableId: string,
@ -71,7 +57,9 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
id: breakRowIdField(id), id: breakRowIdField(id),
row: rowData, row: rowData,
}) })
const row = await getRow(tableId, id, { relationships: true }) const row = await sdk.rows.external.getRow(tableId, id, {
relationships: true,
})
const table = await sdk.tables.getTable(tableId) const table = await sdk.tables.getTable(tableId)
return { return {
...response, ...response,
@ -96,7 +84,9 @@ export async function save(ctx: UserCtx) {
const responseRow = response as { row: Row } const responseRow = response as { row: Row }
const rowId = responseRow.row._id const rowId = responseRow.row._id
if (rowId) { if (rowId) {
const row = await getRow(tableId, rowId, { relationships: true }) const row = await sdk.rows.external.getRow(tableId, rowId, {
relationships: true,
})
return { return {
...response, ...response,
row, row,
@ -109,7 +99,7 @@ export async function save(ctx: UserCtx) {
export async function find(ctx: UserCtx) { export async function find(ctx: UserCtx) {
const id = ctx.params.rowId const id = ctx.params.rowId
const tableId = ctx.params.tableId const tableId = ctx.params.tableId
return getRow(tableId, id) return sdk.rows.external.getRow(tableId, id)
} }
export async function destroy(ctx: UserCtx) { export async function destroy(ctx: UserCtx) {

View File

@ -0,0 +1,17 @@
import { IncludeRelationship, Operation, Row } from "@budibase/types"
import { handleRequest } from "../../../api/controllers/row/external"
import { breakRowIdField } from "../../../integrations/utils"
export async function getRow(
tableId: string,
rowId: string,
opts?: { relationships?: boolean }
) {
const response = (await handleRequest(Operation.READ, tableId, {
id: breakRowIdField(rowId),
includeSqlRelationships: opts?.relationships
? IncludeRelationship.INCLUDE
: IncludeRelationship.EXCLUDE,
})) as Row[]
return response ? response[0] : response
}

View File

@ -2,10 +2,12 @@ import * as attachments from "./attachments"
import * as rows from "./rows" import * as rows from "./rows"
import * as search from "./search" import * as search from "./search"
import * as utils from "./utils" import * as utils from "./utils"
import * as external from "./external"
export default { export default {
...attachments, ...attachments,
...rows, ...rows,
...search, ...search,
utils: utils, utils,
external,
} }