Adding table public API.
This commit is contained in:
parent
8f6e55e65b
commit
aeae61342a
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,7 @@ exports.search = async ctx => {
|
||||||
const { name } = ctx.request.body
|
const { name } = ctx.request.body
|
||||||
const apps = await getAllApps({ all: true })
|
const apps = await getAllApps({ all: true })
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
applications: search(apps, "name", name),
|
applications: search(apps, name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
const { searchDocs } = require("./utils")
|
const { search } = require("./utils")
|
||||||
const { DocumentTypes } = require("../../../db/utils")
|
|
||||||
const queryController = require("../query")
|
const queryController = require("../query")
|
||||||
|
|
||||||
exports.search = async ctx => {
|
exports.search = async ctx => {
|
||||||
|
await queryController.fetch(ctx)
|
||||||
const { name } = ctx.request.body
|
const { name } = ctx.request.body
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
queries: await searchDocs(DocumentTypes.QUERY, "name", name),
|
queries: search(ctx.body, name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,13 @@ exports.read = async ctx => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.update = 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 }
|
ctx.body = { row: ctx.body }
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.delete = async ctx => {
|
exports.delete = async ctx => {
|
||||||
// set the body as expected, with the _id and _rev fields
|
// 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)
|
await rowController.destroy(ctx)
|
||||||
// destroy controller doesn't currently return the row as the body, need to adjust this
|
// destroy controller doesn't currently return the row as the body, need to adjust this
|
||||||
// in the public API to be correct
|
// in the public API to be correct
|
||||||
|
|
|
@ -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 }
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
const { getAppDB } = require("@budibase/backend-core/context")
|
||||||
const { getDocParams } = require("@budibase/backend-core/db")
|
const { isExternalTable } = require("../../../integrations/utils")
|
||||||
|
|
||||||
exports.addRev = async body => {
|
exports.addRev = async (body, tableId) => {
|
||||||
if (!body._id) {
|
if (!body._id || isExternalTable(tableId)) {
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
const db = getAppDB()
|
const db = getAppDB()
|
||||||
|
@ -11,7 +11,12 @@ exports.addRev = async body => {
|
||||||
return 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") {
|
if (!value || typeof value !== "string") {
|
||||||
return docs
|
return docs
|
||||||
}
|
}
|
||||||
|
@ -28,20 +33,3 @@ exports.search = (docs, key, value) => {
|
||||||
}
|
}
|
||||||
return filtered
|
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ exports.fetch = async function (ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.find = async function (ctx) {
|
exports.find = async function (ctx) {
|
||||||
const tableId = ctx.params.id
|
const tableId = ctx.params.tableId
|
||||||
ctx.body = await getTable(tableId)
|
ctx.body = await getTable(tableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ exports.destroy = async function (ctx) {
|
||||||
ctx.eventEmitter &&
|
ctx.eventEmitter &&
|
||||||
ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
|
ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
|
ctx.table = deletedTable
|
||||||
ctx.body = { message: `Table ${tableId} deleted.` }
|
ctx.body = { message: `Table ${tableId} deleted.` }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ router
|
||||||
* @apiSuccess {object[]} body The response body will be the table that was found.
|
* @apiSuccess {object[]} body The response body will be the table that was found.
|
||||||
*/
|
*/
|
||||||
.get(
|
.get(
|
||||||
"/api/tables/:id",
|
"/api/tables/:tableId",
|
||||||
paramResource("id"),
|
paramResource("tableId"),
|
||||||
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
||||||
tableController.find
|
tableController.find
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue