1
0
Fork 0
mirror of synced 2024-06-26 18:10:51 +12:00

Adding table public API.

This commit is contained in:
Michael Drury 2022-02-23 22:13:16 +00:00
parent c189550614
commit 88e0f67f42
9 changed files with 69 additions and 2402 deletions

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@ exports.search = async ctx => {
const { name } = ctx.request.body
const apps = await getAllApps({ all: true })
ctx.body = {
applications: search(apps, "name", name),
applications: search(apps, name),
}
}

View file

@ -1,11 +1,11 @@
const { searchDocs } = require("./utils")
const { DocumentTypes } = require("../../../db/utils")
const { search } = require("./utils")
const queryController = require("../query")
exports.search = async ctx => {
await queryController.fetch(ctx)
const { name } = ctx.request.body
ctx.body = {
queries: await searchDocs(DocumentTypes.QUERY, "name", name),
queries: search(ctx.body, name),
}
}

View file

@ -35,13 +35,13 @@ exports.read = async ctx => {
}
exports.update = async ctx => {
ctx.request.body = await addRev(fixRow(ctx.request.body, ctx.params))
ctx.request.body = await addRev(fixRow(ctx.request.body, ctx.params.tableId))
ctx.body = { row: ctx.body }
}
exports.delete = async ctx => {
// set the body as expected, with the _id and _rev fields
ctx.request.body = await addRev({ _id: ctx.params.rowId })
ctx.request.body = await addRev(fixRow({}, ctx.params.tableId))
await rowController.destroy(ctx)
// destroy controller doesn't currently return the row as the body, need to adjust this
// in the public API to be correct

View file

@ -1,9 +1,31 @@
exports.search = () => {}
const { search, addRev } = require("./utils")
const controller = require("../table")
exports.create = () => {}
exports.search = async ctx => {
const { name } = ctx.request.body
await controller.fetch(ctx)
ctx.body = {
tables: search(ctx.body, name),
}
}
exports.read = () => {}
exports.create = async ctx => {
await controller.save(ctx)
ctx.body = { table: ctx.body }
}
exports.update = () => {}
exports.read = async ctx => {
await controller.find(ctx)
ctx.body = { table: ctx.body }
}
exports.delete = () => {}
exports.update = async ctx => {
ctx.request.body = await addRev(ctx.request.body, ctx.params.tableId)
await controller.save(ctx)
ctx.body = { table: ctx.body }
}
exports.delete = async ctx => {
await controller.destroy(ctx)
ctx.body = { table: ctx.table }
}

View file

@ -1,8 +1,8 @@
const { getAppDB } = require("@budibase/backend-core/context")
const { getDocParams } = require("@budibase/backend-core/db")
const { isExternalTable } = require("../../../integrations/utils")
exports.addRev = async body => {
if (!body._id) {
exports.addRev = async (body, tableId) => {
if (!body._id || isExternalTable(tableId)) {
return body
}
const db = getAppDB()
@ -11,7 +11,12 @@ exports.addRev = async body => {
return body
}
exports.search = (docs, key, value) => {
/**
* Performs a case insensitive search on the provided documents, using the
* provided key and value. This will be a string based search, using the
* startsWith function.
*/
exports.search = (docs, value, key = "name") => {
if (!value || typeof value !== "string") {
return docs
}
@ -28,20 +33,3 @@ exports.search = (docs, key, value) => {
}
return filtered
}
/**
* Performs a case insensitive search on a document type, using the
* provided key and value. This will be a string based search,
* using the startsWith function.
*/
exports.searchDocs = async (docType, key, value) => {
const db = getAppDB()
const docs = (
await db.allDocs(
getDocParams(docType, null, {
include_docs: true,
})
)
).rows.map(row => row.doc)
return exports.search(docs, key, value)
}

View file

@ -48,7 +48,7 @@ exports.fetch = async function (ctx) {
}
exports.find = async function (ctx) {
const tableId = ctx.params.id
const tableId = ctx.params.tableId
ctx.body = await getTable(tableId)
}
@ -70,6 +70,7 @@ exports.destroy = async function (ctx) {
ctx.eventEmitter &&
ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
ctx.status = 200
ctx.table = deletedTable
ctx.body = { message: `Table ${tableId} deleted.` }
}

View file

@ -53,8 +53,8 @@ router
* @apiSuccess {object[]} body The response body will be the table that was found.
*/
.get(
"/api/tables/:id",
paramResource("id"),
"/api/tables/:tableId",
paramResource("tableId"),
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
tableController.find
)

File diff suppressed because it is too large Load diff