Implement get view
This commit is contained in:
parent
1187bd8fb2
commit
7155d75906
3 changed files with 39 additions and 0 deletions
|
@ -6,6 +6,11 @@ export async function fetch(ctx: Ctx) {
|
||||||
ctx.body = { views: await sdk.views.fetch() }
|
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) {
|
export async function findByTable(ctx: Ctx) {
|
||||||
const tableId = `${DocumentType.TABLE}${SEPARATOR}${ctx.params.tableId}`
|
const tableId = `${DocumentType.TABLE}${SEPARATOR}${ctx.params.tableId}`
|
||||||
ctx.body = { views: await sdk.views.findByTable(tableId) }
|
ctx.body = { views: await sdk.views.findByTable(tableId) }
|
||||||
|
|
|
@ -45,6 +45,14 @@ describe("/views/v2", () => {
|
||||||
.expect(200)
|
.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 {
|
function createView(tableId: string): ViewV2 {
|
||||||
return {
|
return {
|
||||||
name: generator.guid(),
|
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", () => {
|
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 view = createView(table._id!)
|
const view = createView(table._id!)
|
||||||
|
|
|
@ -18,6 +18,11 @@ router
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
viewController.v2.findByTable
|
viewController.v2.findByTable
|
||||||
)
|
)
|
||||||
|
.get(
|
||||||
|
`/api/views/v2/${DocumentType.VIEW}${SEPARATOR}:viewId`,
|
||||||
|
authorized(permissions.BUILDER),
|
||||||
|
viewController.v2.find
|
||||||
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/views/v2",
|
"/api/views/v2",
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
|
|
Loading…
Reference in a new issue