Remove fetch view
This commit is contained in:
parent
56ee61d76c
commit
d6121d1504
|
@ -1,19 +1,6 @@
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { CreateViewRequest, Ctx, ViewResponse } from "@budibase/types"
|
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>) {
|
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
|
||||||
const { tableId } = ctx.params
|
const { tableId } = ctx.params
|
||||||
const view = ctx.request.body
|
const view = ctx.request.body
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator, structures } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
function priceTable(): Table {
|
function priceTable(): Table {
|
||||||
return {
|
return {
|
||||||
|
@ -50,36 +50,6 @@ describe("/v2/views", () => {
|
||||||
await config.createTable(priceTable())
|
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", () => {
|
describe("create", () => {
|
||||||
it("persist the view when the view is successfully created", async () => {
|
it("persist the view when the view is successfully created", async () => {
|
||||||
const newView: CreateViewRequest = {
|
const newView: CreateViewRequest = {
|
||||||
|
|
|
@ -8,11 +8,6 @@ import { DocumentType, SEPARATOR, permissions } from "@budibase/backend-core"
|
||||||
const router: Router = new Router()
|
const router: Router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get(
|
|
||||||
`/api/v2/views/:viewId`,
|
|
||||||
authorized(permissions.BUILDER),
|
|
||||||
viewController.v2.find
|
|
||||||
)
|
|
||||||
.post(
|
.post(
|
||||||
"/api/v2/views/:tableId",
|
"/api/v2/views/:tableId",
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
|
|
|
@ -1,23 +1,9 @@
|
||||||
import { HTTPError, context } from "@budibase/backend-core"
|
import { HTTPError, context } from "@budibase/backend-core"
|
||||||
import { ViewV2 } from "@budibase/types"
|
import { ViewV2 } from "@budibase/types"
|
||||||
import * as utils from "../../../db/utils"
|
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { utils as coreUtils } from "@budibase/backend-core"
|
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(
|
export async function create(
|
||||||
tableId: string,
|
tableId: string,
|
||||||
viewRequest: Omit<ViewV2, "id" | "version">
|
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> {
|
export async function remove(tableId: string, viewId: string): Promise<void> {
|
||||||
const db = context.getAppDB()
|
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 table = await sdk.tables.getTable(tableId)
|
||||||
const view = Object.values(table.views!).find(v => isV2(v) && v.id === viewId)
|
const view = Object.values(table.views!).find(v => isV2(v) && v.id === viewId)
|
||||||
if (!view) {
|
if (!view) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { ViewV2 } from "@budibase/types"
|
||||||
import TestConfiguration from "../TestConfiguration"
|
import TestConfiguration from "../TestConfiguration"
|
||||||
import { TestAPI } from "./base"
|
import { TestAPI } from "./base"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import supertest from "supertest"
|
|
||||||
|
|
||||||
export class ViewV2API extends TestAPI {
|
export class ViewV2API extends TestAPI {
|
||||||
constructor(config: TestConfiguration) {
|
constructor(config: TestConfiguration) {
|
||||||
|
@ -32,17 +31,6 @@ export class ViewV2API extends TestAPI {
|
||||||
return result.body.data as ViewV2
|
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 (
|
delete = async (
|
||||||
tableId: string,
|
tableId: string,
|
||||||
viewId: string,
|
viewId: string,
|
||||||
|
|
Loading…
Reference in New Issue