From d6121d1504896a3ff40fdcbe6dba1441426aa3ca Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 19 Jul 2023 15:49:46 +0200 Subject: [PATCH] Remove fetch view --- .../src/api/controllers/view/viewsV2.ts | 13 -------- .../src/api/routes/tests/viewV2.spec.ts | 32 +------------------ packages/server/src/api/routes/view.ts | 5 --- packages/server/src/sdk/app/views/index.ts | 19 +---------- .../server/src/tests/utilities/api/viewV2.ts | 12 ------- 5 files changed, 2 insertions(+), 79 deletions(-) diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index 3a8b0980b4..597dc54e66 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -1,19 +1,6 @@ import sdk from "../../../sdk" import { CreateViewRequest, Ctx, ViewResponse } from "@budibase/types" -export async function find(ctx: Ctx) { - 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) { const { tableId } = ctx.params const view = ctx.request.body diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index dd3cf3b658..7dc4fc1bad 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -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 = { diff --git a/packages/server/src/api/routes/view.ts b/packages/server/src/api/routes/view.ts index 54ba54c431..010168aa13 100644 --- a/packages/server/src/api/routes/view.ts +++ b/packages/server/src/api/routes/view.ts @@ -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), diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index 3d7e21d448..b4bb382bb3 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -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 { - const db = context.getAppDB() - try { - const result = await db.get(viewId) - return result - } catch (err: any) { - if (err.status === 404) { - return undefined - } - - throw err - } -} - export async function create( tableId: string, viewRequest: Omit @@ -49,9 +35,6 @@ function isV2(view: object): view is ViewV2 { export async function remove(tableId: string, viewId: string): Promise { 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) { diff --git a/packages/server/src/tests/utilities/api/viewV2.ts b/packages/server/src/tests/utilities/api/viewV2.ts index c2d2a79292..e40bfe7030 100644 --- a/packages/server/src/tests/utilities/api/viewV2.ts +++ b/packages/server/src/tests/utilities/api/viewV2.ts @@ -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,