1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00
budibase/packages/server/src/api/controllers/public/tables.ts

51 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-02-25 04:13:14 +13:00
import { search as stringSearch, addRev } from "./utils"
import { default as controller } from "../table"
2022-02-26 08:00:12 +13:00
import { Table } from "../../../definitions/common"
function fixTable(table: Table, params: any) {
if (!params || !table) {
return table
}
if (params.tableId) {
table._id = params.tableId
}
return table
}
2022-02-25 04:13:14 +13:00
export async function search(ctx: any) {
2022-02-24 11:13:16 +13:00
const { name } = ctx.request.body
await controller.fetch(ctx)
ctx.body = {
2022-02-25 04:13:14 +13:00
tables: stringSearch(ctx.body, name),
2022-02-24 11:13:16 +13:00
}
}
2022-02-25 04:13:14 +13:00
export async function create(ctx: any) {
2022-02-24 11:13:16 +13:00
await controller.save(ctx)
ctx.body = { table: ctx.body }
}
2022-02-25 04:13:14 +13:00
export async function read(ctx: any) {
2022-02-24 11:13:16 +13:00
await controller.find(ctx)
ctx.body = { table: ctx.body }
}
2022-02-25 04:13:14 +13:00
export async function update(ctx: any) {
2022-02-26 08:00:12 +13:00
ctx.request.body = await addRev(fixTable(ctx.request.body, ctx.params), ctx.params.tableId)
2022-02-24 11:13:16 +13:00
await controller.save(ctx)
ctx.body = { table: ctx.body }
}
2022-02-25 04:13:14 +13:00
export async function destroy(ctx: any) {
2022-02-24 11:13:16 +13:00
await controller.destroy(ctx)
ctx.body = { table: ctx.table }
}
2022-02-25 04:13:14 +13:00
export default {
create,
read,
update,
destroy,
search,
}