Implement get view

This commit is contained in:
Adria Navarro 2023-07-12 17:48:11 +02:00
parent 1187bd8fb2
commit 7155d75906
3 changed files with 39 additions and 0 deletions

View File

@ -6,6 +6,11 @@ export async function fetch(ctx: Ctx) {
ctx.body = { views: await sdk.views.fetch() }
}
export async function find(ctx: Ctx) {
const viewId = `${DocumentType.VIEW}${SEPARATOR}${ctx.params.viewId}`
ctx.body = await sdk.views.get(viewId)
}
export async function findByTable(ctx: Ctx) {
const tableId = `${DocumentType.TABLE}${SEPARATOR}${ctx.params.tableId}`
ctx.body = { views: await sdk.views.findByTable(tableId) }

View File

@ -45,6 +45,14 @@ describe("/views/v2", () => {
.expect(200)
}
const getView = async (viewId: string) => {
return request
.get(`/api/views/v2/${viewId}`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
}
function createView(tableId: string): ViewV2 {
return {
name: generator.guid(),
@ -100,6 +108,27 @@ describe("/views/v2", () => {
})
})
describe("getView", () => {
let view: any
beforeAll(async () => {
view = (await saveView(createView(table._id!))).body
})
it("persist the view when the view is successfully created", async () => {
const res = await getView(view._id)
expect(res.status).toBe(200)
expect(res.body._id).toBeDefined()
expect(res.body).toEqual({
...view,
_id: expect.any(String),
_rev: expect.any(String),
createdAt: expect.any(String),
updatedAt: expect.any(String),
})
})
})
describe("create", () => {
it("persist the view when the view is successfully created", async () => {
const view = createView(table._id!)

View File

@ -18,6 +18,11 @@ router
authorized(permissions.BUILDER),
viewController.v2.findByTable
)
.get(
`/api/views/v2/${DocumentType.VIEW}${SEPARATOR}:viewId`,
authorized(permissions.BUILDER),
viewController.v2.find
)
.post(
"/api/views/v2",
authorized(permissions.BUILDER),