1
0
Fork 0
mirror of synced 2024-10-03 02:27:06 +13:00

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"
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(
operation: Operation,
tableId: string,
@ -71,7 +57,9 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
id: breakRowIdField(id),
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)
return {
...response,
@ -96,7 +84,9 @@ export async function save(ctx: UserCtx) {
const responseRow = response as { row: Row }
const rowId = responseRow.row._id
if (rowId) {
const row = await getRow(tableId, rowId, { relationships: true })
const row = await sdk.rows.external.getRow(tableId, rowId, {
relationships: true,
})
return {
...response,
row,
@ -109,7 +99,7 @@ export async function save(ctx: UserCtx) {
export async function find(ctx: UserCtx) {
const id = ctx.params.rowId
const tableId = ctx.params.tableId
return getRow(tableId, id)
return sdk.rows.external.getRow(tableId, id)
}
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 search from "./search"
import * as utils from "./utils"
import * as external from "./external"
export default {
...attachments,
...rows,
...search,
utils: utils,
utils,
external,
}