Remove view endpoint
This commit is contained in:
parent
22dd218b1a
commit
3f2fa1a8dc
|
@ -1,10 +1,5 @@
|
|||
import sdk from "../../../sdk"
|
||||
import {
|
||||
CreateViewRequest,
|
||||
Ctx,
|
||||
ViewResponse,
|
||||
ViewSchemaResponse,
|
||||
} from "@budibase/types"
|
||||
import { CreateViewRequest, Ctx, ViewResponse } from "@budibase/types"
|
||||
|
||||
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
|
||||
const view = ctx.request.body
|
||||
|
@ -23,10 +18,3 @@ export async function remove(ctx: Ctx) {
|
|||
await sdk.views.remove(viewId)
|
||||
ctx.status = 204
|
||||
}
|
||||
|
||||
export async function getSchema(ctx: Ctx<void, ViewSchemaResponse>) {
|
||||
const { viewId } = ctx.params
|
||||
|
||||
const schema = await sdk.views.getSchema(viewId)
|
||||
ctx.body = { schema }
|
||||
}
|
||||
|
|
|
@ -112,74 +112,74 @@ describe("/v2/views", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("getSchema", () => {
|
||||
beforeAll(async () => {
|
||||
await config.createTable(priceTable())
|
||||
})
|
||||
// describe("getSchema", () => {
|
||||
// beforeAll(async () => {
|
||||
// await config.createTable(priceTable())
|
||||
// })
|
||||
|
||||
it("returns table schema if no columns are defined", async () => {
|
||||
const view = await config.api.viewV2.create()
|
||||
const result = await config.api.viewV2.getSchema(view.id)
|
||||
expect(result).toEqual({
|
||||
schema: {
|
||||
Price: {
|
||||
type: "number",
|
||||
name: "Price",
|
||||
constraints: {},
|
||||
},
|
||||
Currency: {
|
||||
type: "string",
|
||||
name: "Currency",
|
||||
constraints: {},
|
||||
},
|
||||
ItemId: {
|
||||
type: "string",
|
||||
name: "ItemId",
|
||||
constraints: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
// it("returns table schema if no columns are defined", async () => {
|
||||
// const view = await config.api.viewV2.create()
|
||||
// const result = await config.api.viewV2.getSchema(view.id)
|
||||
// expect(result).toEqual({
|
||||
// schema: {
|
||||
// Price: {
|
||||
// type: "number",
|
||||
// name: "Price",
|
||||
// constraints: {},
|
||||
// },
|
||||
// Currency: {
|
||||
// type: "string",
|
||||
// name: "Currency",
|
||||
// constraints: {},
|
||||
// },
|
||||
// ItemId: {
|
||||
// type: "string",
|
||||
// name: "ItemId",
|
||||
// constraints: {
|
||||
// type: "string",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// })
|
||||
|
||||
it("respects view column definition if exists", async () => {
|
||||
const view = await config.api.viewV2.create({
|
||||
columns: ["Price", "ItemId"],
|
||||
})
|
||||
const result = await config.api.viewV2.getSchema(view.id)
|
||||
expect(result).toEqual({
|
||||
schema: {
|
||||
Price: {
|
||||
type: "number",
|
||||
name: "Price",
|
||||
constraints: {},
|
||||
},
|
||||
ItemId: {
|
||||
type: "string",
|
||||
name: "ItemId",
|
||||
constraints: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
// it("respects view column definition if exists", async () => {
|
||||
// const view = await config.api.viewV2.create({
|
||||
// columns: ["Price", "ItemId"],
|
||||
// })
|
||||
// const result = await config.api.viewV2.getSchema(view.id)
|
||||
// expect(result).toEqual({
|
||||
// schema: {
|
||||
// Price: {
|
||||
// type: "number",
|
||||
// name: "Price",
|
||||
// constraints: {},
|
||||
// },
|
||||
// ItemId: {
|
||||
// type: "string",
|
||||
// name: "ItemId",
|
||||
// constraints: {
|
||||
// type: "string",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// })
|
||||
|
||||
it("respects view column definition if exists", async () => {
|
||||
const view = await config.api.viewV2.create({
|
||||
columns: ["Price", "innexistingColumn"],
|
||||
})
|
||||
const result = await config.api.viewV2.getSchema(view.id)
|
||||
expect(result).toEqual({
|
||||
schema: {
|
||||
Price: {
|
||||
type: "number",
|
||||
name: "Price",
|
||||
constraints: {},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
// it("respects view column definition if exists", async () => {
|
||||
// const view = await config.api.viewV2.create({
|
||||
// columns: ["Price", "innexistingColumn"],
|
||||
// })
|
||||
// const result = await config.api.viewV2.getSchema(view.id)
|
||||
// expect(result).toEqual({
|
||||
// schema: {
|
||||
// Price: {
|
||||
// type: "number",
|
||||
// name: "Price",
|
||||
// constraints: {},
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
})
|
||||
|
|
|
@ -18,11 +18,6 @@ router
|
|||
authorized(permissions.BUILDER),
|
||||
viewController.v2.remove
|
||||
)
|
||||
.get(
|
||||
`/api/v2/views/:viewId/schema`,
|
||||
authorized(permissions.BUILDER),
|
||||
viewController.v2.getSchema
|
||||
)
|
||||
|
||||
router
|
||||
.get(
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { HTTPError, context } from "@budibase/backend-core"
|
||||
import { TableSchema, View, ViewV2 } from "@budibase/types"
|
||||
import { View, ViewV2 } from "@budibase/types"
|
||||
|
||||
import sdk from "../../../sdk"
|
||||
import * as utils from "../../../db/utils"
|
||||
import _ from "lodash"
|
||||
|
||||
export async function get(viewId: string): Promise<ViewV2 | undefined> {
|
||||
const { tableId } = utils.extractViewInfoFromID(viewId)
|
||||
|
@ -49,15 +48,3 @@ export async function remove(viewId: string): Promise<void> {
|
|||
delete table.views![view?.name]
|
||||
await db.put(table)
|
||||
}
|
||||
|
||||
export async function getSchema(viewId: string): Promise<TableSchema> {
|
||||
const view = await get(viewId)
|
||||
const table = await sdk.tables.getTable(view?.tableId)
|
||||
|
||||
if (!view?.columns?.length) {
|
||||
return table.schema
|
||||
}
|
||||
|
||||
const schema = _.pick(table.schema, ...view.columns)
|
||||
return schema
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ViewSchemaResponse, ViewV2 } from "@budibase/types"
|
||||
import { ViewV2 } from "@budibase/types"
|
||||
import TestConfiguration from "../TestConfiguration"
|
||||
import { TestAPI } from "./base"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
@ -38,17 +38,6 @@ export class ViewV2API extends TestAPI {
|
|||
.expect(expectStatus)
|
||||
}
|
||||
|
||||
getSchema = async (
|
||||
viewId: string,
|
||||
{ expectStatus } = { expectStatus: 200 }
|
||||
): Promise<ViewSchemaResponse> => {
|
||||
const res = await this.request
|
||||
.get(`/api/v2/views/${viewId}/schema`)
|
||||
.set(this.config.defaultHeaders())
|
||||
.expect(expectStatus)
|
||||
return res.body
|
||||
}
|
||||
|
||||
search = async (viewId: string, { expectStatus } = { expectStatus: 200 }) => {
|
||||
return this.request
|
||||
.get(`/api/v2/views/${viewId}/search`)
|
||||
|
|
|
@ -5,7 +5,3 @@ export interface ViewResponse {
|
|||
}
|
||||
|
||||
export type CreateViewRequest = Omit<ViewV2, "version" | "id">
|
||||
|
||||
export interface ViewSchemaResponse {
|
||||
schema: TableSchema
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue