Remove fetch view

This commit is contained in:
Adria Navarro 2023-07-19 15:49:46 +02:00
parent 56ee61d76c
commit d6121d1504
5 changed files with 2 additions and 79 deletions

View File

@ -1,19 +1,6 @@
import sdk from "../../../sdk"
import { CreateViewRequest, Ctx, ViewResponse } from "@budibase/types"
export async function find(ctx: Ctx<void, ViewResponse>) {
const { viewId } = ctx.params
const view = await sdk.views.get(viewId)
if (!view) {
ctx.throw(404)
}
ctx.body = {
data: view,
}
}
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
const { tableId } = ctx.params
const view = ctx.request.body

View File

@ -7,7 +7,7 @@ import {
Table,
ViewV2,
} from "@budibase/types"
import { generator, structures } from "@budibase/backend-core/tests"
import { generator } from "@budibase/backend-core/tests"
function priceTable(): Table {
return {
@ -50,36 +50,6 @@ describe("/v2/views", () => {
await config.createTable(priceTable())
})
describe("getView", () => {
let view: ViewV2
beforeAll(async () => {
view = await config.api.viewV2.create(config.table?._id, {
query: { allOr: false, notEqual: { field: "value" } },
})
})
it("can fetch the expected view", async () => {
const res = await config.api.viewV2.get(view.id)
expect(res.status).toBe(200)
expect(res.body).toEqual({
data: {
...view,
_id: view._id,
_rev: expect.any(String),
createdAt: expect.any(String),
updatedAt: expect.any(String),
},
})
})
it("will return 404 if the unnexisting id is provided", async () => {
await config.api.viewV2.get(structures.generator.guid(), {
expectStatus: 404,
})
})
})
describe("create", () => {
it("persist the view when the view is successfully created", async () => {
const newView: CreateViewRequest = {

View File

@ -8,11 +8,6 @@ import { DocumentType, SEPARATOR, permissions } from "@budibase/backend-core"
const router: Router = new Router()
router
.get(
`/api/v2/views/:viewId`,
authorized(permissions.BUILDER),
viewController.v2.find
)
.post(
"/api/v2/views/:tableId",
authorized(permissions.BUILDER),

View File

@ -1,23 +1,9 @@
import { HTTPError, context } from "@budibase/backend-core"
import { ViewV2 } from "@budibase/types"
import * as utils from "../../../db/utils"
import sdk from "../../../sdk"
import { utils as coreUtils } from "@budibase/backend-core"
export async function get(viewId: string): Promise<ViewV2 | undefined> {
const db = context.getAppDB()
try {
const result = await db.get<ViewV2>(viewId)
return result
} catch (err: any) {
if (err.status === 404) {
return undefined
}
throw err
}
}
export async function create(
tableId: string,
viewRequest: Omit<ViewV2, "id" | "version">
@ -49,9 +35,6 @@ function isV2(view: object): view is ViewV2 {
export async function remove(tableId: string, viewId: string): Promise<void> {
const db = context.getAppDB()
const doc = await sdk.views.get(viewId)
await db.remove(viewId, doc!._rev)
const table = await sdk.tables.getTable(tableId)
const view = Object.values(table.views!).find(v => isV2(v) && v.id === viewId)
if (!view) {

View File

@ -2,7 +2,6 @@ import { ViewV2 } from "@budibase/types"
import TestConfiguration from "../TestConfiguration"
import { TestAPI } from "./base"
import { generator } from "@budibase/backend-core/tests"
import supertest from "supertest"
export class ViewV2API extends TestAPI {
constructor(config: TestConfiguration) {
@ -32,17 +31,6 @@ export class ViewV2API extends TestAPI {
return result.body.data as ViewV2
}
get = (
viewId: string,
{ expectStatus } = { expectStatus: 200 }
): supertest.Test => {
return this.request
.get(`/api/v2/views/${viewId}`)
.set(this.config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(expectStatus)
}
delete = async (
tableId: string,
viewId: string,