Type view search
This commit is contained in:
parent
259bb3cdc2
commit
4f08f900ed
|
@ -2,13 +2,15 @@ import { quotas } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
UserCtx,
|
UserCtx,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
SearchRowRequest,
|
|
||||||
SearchRowResponse,
|
SearchRowResponse,
|
||||||
|
SearchViewRowRequest,
|
||||||
|
RequiredKeys,
|
||||||
|
SearchParams,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
|
|
||||||
export async function searchView(
|
export async function searchView(
|
||||||
ctx: UserCtx<SearchRowRequest, SearchRowResponse>
|
ctx: UserCtx<SearchViewRowRequest, SearchRowResponse>
|
||||||
) {
|
) {
|
||||||
const { viewId } = ctx.params
|
const { viewId } = ctx.params
|
||||||
|
|
||||||
|
@ -30,24 +32,24 @@ export async function searchView(
|
||||||
undefined
|
undefined
|
||||||
|
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
const result = await quotas.addQuery(
|
|
||||||
() =>
|
const searchOptions: RequiredKeys<SearchViewRowRequest> &
|
||||||
sdk.rows.search({
|
RequiredKeys<Pick<SearchParams, "tableId" | "query" | "fields">> = {
|
||||||
tableId: view.tableId,
|
tableId: view.tableId,
|
||||||
query: view.query || {},
|
query: view.query || {},
|
||||||
fields: viewFields,
|
fields: viewFields,
|
||||||
...getSortOptions(ctx.request.body, view),
|
...getSortOptions(ctx.request.body, view),
|
||||||
}),
|
}
|
||||||
{
|
|
||||||
datasourceId: view.tableId,
|
const result = await quotas.addQuery(() => sdk.rows.search(searchOptions), {
|
||||||
}
|
datasourceId: view.tableId,
|
||||||
)
|
})
|
||||||
|
|
||||||
result.rows.forEach(r => (r._viewId = view.id))
|
result.rows.forEach(r => (r._viewId = view.id))
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSortOptions(request: SearchRowRequest, view: ViewV2) {
|
function getSortOptions(request: SearchViewRowRequest, view: ViewV2) {
|
||||||
if (request.sort) {
|
if (request.sort) {
|
||||||
return {
|
return {
|
||||||
sort: request.sort,
|
sort: request.sort,
|
||||||
|
@ -63,5 +65,9 @@ function getSortOptions(request: SearchRowRequest, view: ViewV2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined
|
return {
|
||||||
|
sort: undefined,
|
||||||
|
sortOrder: undefined,
|
||||||
|
sortType: undefined,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue