Enrich on get row from view
This commit is contained in:
parent
e443b00a69
commit
6b259676b2
|
@ -115,10 +115,11 @@ export async function fetch(ctx: any) {
|
|||
}
|
||||
|
||||
export async function find(ctx: UserCtx<void, GetRowResponse>) {
|
||||
const { tableId } = utils.getSourceId(ctx)
|
||||
const { sourceId } = ctx.params
|
||||
const rowId = ctx.params.rowId
|
||||
|
||||
ctx.body = await sdk.rows.find(tableId, rowId)
|
||||
const response = await sdk.rows.find(sourceId, rowId)
|
||||
ctx.body = response
|
||||
}
|
||||
|
||||
function isDeleteRows(input: any): input is DeleteRows {
|
||||
|
|
|
@ -2596,7 +2596,7 @@ describe.each([
|
|||
})
|
||||
|
||||
const testScenarios: [string, (row: Row) => Promise<Row> | Row][] = [
|
||||
// ["get row", (row: Row) => config.api.row.get(viewId, row._id!)],
|
||||
["get row", (row: Row) => config.api.row.get(viewId, row._id!)],
|
||||
// [
|
||||
// "fetch",
|
||||
// async (row: Row) => {
|
||||
|
@ -2690,7 +2690,7 @@ describe.each([
|
|||
async () => {
|
||||
const otherRows = _.sampleSize(auxData, 5)
|
||||
|
||||
const row = await config.api.row.save(tableId, {
|
||||
const row = await config.api.row.save(viewId, {
|
||||
title: generator.word(),
|
||||
relWithNoSchema: [otherRows[0]],
|
||||
relWithEmptySchema: [otherRows[1]],
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
} from "../../../utilities/rowProcessor"
|
||||
import cloneDeep from "lodash/fp/cloneDeep"
|
||||
import isEqual from "lodash/fp/isEqual"
|
||||
import { tryExtractingTableAndViewId } from "./utils"
|
||||
|
||||
export async function getRow(
|
||||
tableId: string,
|
||||
|
@ -70,7 +71,9 @@ export async function save(
|
|||
}
|
||||
}
|
||||
|
||||
export async function find(tableId: string, rowId: string): Promise<Row> {
|
||||
export async function find(tableOrViewId: string, rowId: string): Promise<Row> {
|
||||
const { tableId, viewId } = tryExtractingTableAndViewId(tableOrViewId)
|
||||
|
||||
const row = await getRow(tableId, rowId, {
|
||||
relationships: true,
|
||||
})
|
||||
|
@ -84,5 +87,6 @@ export async function find(tableId: string, rowId: string): Promise<Row> {
|
|||
return await outputProcessing(table, row, {
|
||||
squash: true,
|
||||
preserveLinks: true,
|
||||
fromViewId: viewId,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
import * as linkRows from "../../../db/linkedRows"
|
||||
import { InternalTables } from "../../../db/utils"
|
||||
import { getFullUser } from "../../../utilities/users"
|
||||
import { tryExtractingTableAndViewId } from "./utils"
|
||||
|
||||
export async function save(
|
||||
tableId: string,
|
||||
|
@ -53,11 +54,13 @@ export async function save(
|
|||
})
|
||||
}
|
||||
|
||||
export async function find(tableId: string, rowId: string): Promise<Row> {
|
||||
export async function find(tableOrViewId: string, rowId: string): Promise<Row> {
|
||||
const { tableId, viewId } = tryExtractingTableAndViewId(tableOrViewId)
|
||||
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
let row = await findRow(tableId, rowId)
|
||||
|
||||
row = await outputProcessing(table, row)
|
||||
row = await outputProcessing(table, row, { squash: true, fromViewId: viewId })
|
||||
return row
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { db as dbCore, context } from "@budibase/backend-core"
|
||||
import { Database, Row } from "@budibase/types"
|
||||
import { getRowParams } from "../../../db/utils"
|
||||
import {
|
||||
extractViewInfoFromID,
|
||||
getRowParams,
|
||||
isViewID,
|
||||
} from "../../../db/utils"
|
||||
import { isExternalTableID } from "../../../integrations/utils"
|
||||
import * as internal from "./internal"
|
||||
import * as external from "./external"
|
||||
|
@ -20,7 +24,12 @@ export async function getAllInternalRows(appId?: string) {
|
|||
return response.rows.map(row => row.doc) as Row[]
|
||||
}
|
||||
|
||||
function pickApi(tableId: any) {
|
||||
function pickApi(tableOrViewId: string) {
|
||||
let tableId = tableOrViewId
|
||||
if (isViewID(tableOrViewId)) {
|
||||
tableId = extractViewInfoFromID(tableOrViewId).tableId
|
||||
}
|
||||
|
||||
if (isExternalTableID(tableId)) {
|
||||
return external
|
||||
}
|
||||
|
@ -35,6 +44,6 @@ export async function save(
|
|||
return pickApi(tableId).save(tableId, row, userId)
|
||||
}
|
||||
|
||||
export async function find(tableId: string, rowId: string) {
|
||||
return pickApi(tableId).find(tableId, rowId)
|
||||
export async function find(tableOrViewId: string, rowId: string) {
|
||||
return pickApi(tableOrViewId).find(tableOrViewId, rowId)
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ export async function search(
|
|||
}
|
||||
|
||||
response.rows = await outputProcessing(table, response.rows, {
|
||||
squash: true,
|
||||
fromViewId: options.viewId,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,7 +17,11 @@ import {
|
|||
import { makeExternalQuery } from "../../../integrations/base/query"
|
||||
import { Format } from "../../../api/controllers/view/exporters"
|
||||
import sdk from "../.."
|
||||
import { isRelationshipColumn } from "../../../db/utils"
|
||||
import {
|
||||
extractViewInfoFromID,
|
||||
isRelationshipColumn,
|
||||
isViewID,
|
||||
} from "../../../db/utils"
|
||||
import { isSQL } from "../../../integrations/utils"
|
||||
|
||||
const SQL_CLIENT_SOURCE_MAP: Record<SourceName, SqlClient | undefined> = {
|
||||
|
@ -317,3 +321,14 @@ function validateTimeOnlyField(
|
|||
export function isArrayFilter(operator: any): operator is ArrayOperator {
|
||||
return Object.values(ArrayOperator).includes(operator)
|
||||
}
|
||||
|
||||
export function tryExtractingTableAndViewId(tableOrViewId: string) {
|
||||
if (isViewID(tableOrViewId)) {
|
||||
return {
|
||||
tableId: extractViewInfoFromID(tableOrViewId).tableId,
|
||||
viewId: tableOrViewId,
|
||||
}
|
||||
}
|
||||
|
||||
return { tableId: tableOrViewId }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue