Change viewrequest to accept schema
This commit is contained in:
parent
73ded07484
commit
b528257bbe
|
@ -4,13 +4,22 @@ import {
|
|||
Ctx,
|
||||
UpdateViewRequest,
|
||||
ViewResponse,
|
||||
ViewV2,
|
||||
} from "@budibase/types"
|
||||
|
||||
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
|
||||
const view = ctx.request.body
|
||||
const { tableId } = view
|
||||
|
||||
const result = await sdk.views.create(tableId, view)
|
||||
const parsedView: Omit<ViewV2, "id" | "version"> = {
|
||||
name: view.name,
|
||||
tableId: view.tableId,
|
||||
query: view.query,
|
||||
sort: view.sort,
|
||||
columns: view.schema && Object.keys(view.schema),
|
||||
schemaUI: view.schema,
|
||||
}
|
||||
const result = await sdk.views.create(tableId, parsedView)
|
||||
ctx.status = 201
|
||||
ctx.body = {
|
||||
data: result,
|
||||
|
|
|
@ -40,9 +40,10 @@ describe("/v2/views", () => {
|
|||
order: SortOrder.DESCENDING,
|
||||
type: SortType.STRING,
|
||||
},
|
||||
columns: ["name"],
|
||||
schemaUI: {
|
||||
schema: {
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
visible: true,
|
||||
},
|
||||
},
|
||||
|
@ -74,17 +75,61 @@ describe("/v2/views", () => {
|
|||
const newView: CreateViewRequest = {
|
||||
name: generator.name(),
|
||||
tableId: config.table!._id!,
|
||||
...viewFilters,
|
||||
query: viewFilters.query,
|
||||
sort: viewFilters.sort,
|
||||
}
|
||||
delete newView.schema
|
||||
const res = await config.api.viewV2.create(newView)
|
||||
|
||||
expect(res).toEqual({
|
||||
...newView,
|
||||
...viewFilters,
|
||||
query: viewFilters.query,
|
||||
sort: viewFilters.sort,
|
||||
id: expect.any(String),
|
||||
version: 2,
|
||||
})
|
||||
})
|
||||
|
||||
it("persist schema overrides", async () => {
|
||||
const newView: CreateViewRequest = {
|
||||
name: generator.name(),
|
||||
tableId: config.table!._id!,
|
||||
schema: {
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
visible: true,
|
||||
},
|
||||
lastname: {
|
||||
name: "lastname",
|
||||
type: FieldType.STRING,
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const createdView = await config.api.viewV2.create(newView)
|
||||
|
||||
expect(await config.api.viewV2.get(createdView.id)).toEqual({
|
||||
...newView,
|
||||
schema: undefined,
|
||||
columns: ["name", "lastname"],
|
||||
schemaUI: {
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
visible: true,
|
||||
},
|
||||
lastname: {
|
||||
name: "lastname",
|
||||
type: FieldType.STRING,
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
id: createdView.id,
|
||||
version: 2,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
|
|
|
@ -3,6 +3,7 @@ import TestConfiguration from "../TestConfiguration"
|
|||
import { TestAPI } from "./base"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
import { Response } from "superagent"
|
||||
import sdk from "../../../sdk"
|
||||
|
||||
export class ViewV2API extends TestAPI {
|
||||
constructor(config: TestConfiguration) {
|
||||
|
@ -62,6 +63,12 @@ export class ViewV2API extends TestAPI {
|
|||
.expect(expectStatus)
|
||||
}
|
||||
|
||||
get = async (viewId: string) => {
|
||||
return await this.config.doInContext(this.config.appId, () =>
|
||||
sdk.views.get(viewId)
|
||||
)
|
||||
}
|
||||
|
||||
search = async (
|
||||
viewId: string,
|
||||
options?: {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { TableSchema, ViewV2 } from "../../../documents"
|
||||
import { ViewV2, FieldSchema } from "../../../documents"
|
||||
|
||||
export interface ViewResponse {
|
||||
data: ViewV2
|
||||
}
|
||||
|
||||
export type CreateViewRequest = Omit<ViewV2, "version" | "id">
|
||||
export interface CreateViewRequest
|
||||
extends Omit<ViewV2, "version" | "id" | "columns" | "schemaUI"> {
|
||||
schema?: Record<string, FieldSchema>
|
||||
}
|
||||
|
||||
export type UpdateViewRequest = ViewV2
|
||||
|
|
Loading…
Reference in New Issue