Types
This commit is contained in:
parent
1d1ae341b1
commit
2c6725404f
|
@ -12,6 +12,7 @@ import {
|
|||
SearchResponse,
|
||||
SortOrder,
|
||||
SortType,
|
||||
UserCtx,
|
||||
ViewV2,
|
||||
} from "@budibase/types"
|
||||
import * as utils from "./utils"
|
||||
|
@ -29,7 +30,7 @@ function pickApi(tableId: any) {
|
|||
return internal
|
||||
}
|
||||
|
||||
export async function patch(ctx: any): Promise<any> {
|
||||
export async function patch(ctx: UserCtx): Promise<any> {
|
||||
const appId = ctx.appId
|
||||
const tableId = utils.getTableId(ctx)
|
||||
const body = ctx.request.body
|
||||
|
@ -53,7 +54,7 @@ export async function patch(ctx: any): Promise<any> {
|
|||
ctx.message = `${table.name} updated successfully.`
|
||||
ctx.body = row
|
||||
gridSocket?.emitRowUpdate(ctx, row)
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
ctx.throw(400, err)
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +79,7 @@ export const save = async (ctx: any) => {
|
|||
ctx.body = row || squashed
|
||||
gridSocket?.emitRowUpdate(ctx, row || squashed)
|
||||
}
|
||||
|
||||
export async function fetchView(ctx: any) {
|
||||
const tableId = utils.getTableId(ctx)
|
||||
const viewName = decodeURIComponent(ctx.params.viewName)
|
||||
|
|
|
@ -147,8 +147,8 @@ export async function exportRows(
|
|||
export async function fetch(tableId: string) {
|
||||
const db = context.getAppDB()
|
||||
|
||||
let table = await sdk.tables.getTable(tableId)
|
||||
let rows = await getRawTableData(db, tableId)
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
const rows = await getRawTableData(db, tableId)
|
||||
const result = await outputProcessing(table, rows)
|
||||
return result
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ async function getRawTableData(db: Database, tableId: string) {
|
|||
export async function fetchView(
|
||||
viewName: string,
|
||||
options: { calculation: string; group: string; field: string }
|
||||
) {
|
||||
): Promise<Row[]> {
|
||||
// if this is a table view being looked for just transfer to that
|
||||
if (viewName.startsWith(DocumentType.TABLE)) {
|
||||
return fetch(viewName)
|
||||
|
@ -197,7 +197,7 @@ export async function fetchView(
|
|||
)
|
||||
}
|
||||
|
||||
let rows
|
||||
let rows: Row[] = []
|
||||
if (!calculation) {
|
||||
response.rows = response.rows.map(row => row.doc)
|
||||
let table: Table
|
||||
|
|
|
@ -186,18 +186,21 @@ export function inputProcessing(
|
|||
* @param {object} opts used to set some options for the output, such as disabling relationship squashing.
|
||||
* @returns {object[]|object} the enriched rows will be returned.
|
||||
*/
|
||||
export async function outputProcessing(
|
||||
export async function outputProcessing<T extends Row[] | Row>(
|
||||
table: Table,
|
||||
rows: Row[] | Row,
|
||||
rows: T,
|
||||
opts = { squash: true }
|
||||
) {
|
||||
): Promise<T> {
|
||||
let safeRows: Row[]
|
||||
let wasArray = true
|
||||
if (!(rows instanceof Array)) {
|
||||
rows = [rows]
|
||||
safeRows = [rows]
|
||||
wasArray = false
|
||||
} else {
|
||||
safeRows = rows
|
||||
}
|
||||
// attach any linked row information
|
||||
let enriched = await linkRows.attachFullLinkedDocs(table, rows as Row[])
|
||||
let enriched = await linkRows.attachFullLinkedDocs(table, safeRows)
|
||||
|
||||
// process formulas
|
||||
enriched = processFormulas(table, enriched, { dynamic: true }) as Row[]
|
||||
|
@ -221,7 +224,7 @@ export async function outputProcessing(
|
|||
enriched
|
||||
)) as Row[]
|
||||
}
|
||||
return wasArray ? enriched : enriched[0]
|
||||
return (wasArray ? enriched : enriched[0]) as T
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue