1
0
Fork 0
mirror of synced 2024-05-29 08:39:46 +12:00
budibase/packages/server/src/api/controllers/public/tables.ts

57 lines
1.1 KiB
TypeScript
Raw Normal View History

import { search as stringSearch, addRev } from "./utils"
2022-02-25 04:13:14 +13:00
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
}
if (!table.type) {
table.type = "table"
}
2022-02-26 08:00:12 +13:00
return table
}
export async function search(ctx: any, next: any) {
2022-02-24 11:13:16 +13:00
const { name } = ctx.request.body
await controller.fetch(ctx)
ctx.body = stringSearch(ctx.body, name)
await next()
2022-02-24 11:13:16 +13:00
}
export async function create(ctx: any, next: any) {
2022-02-24 11:13:16 +13:00
await controller.save(ctx)
await next()
2022-02-24 11:13:16 +13:00
}
export async function read(ctx: any, next: any) {
2022-02-24 11:13:16 +13:00
await controller.find(ctx)
await next()
2022-02-24 11:13:16 +13:00
}
export async function update(ctx: any, next: any) {
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)
await next()
2022-02-24 11:13:16 +13:00
}
export async function destroy(ctx: any, next: any) {
2022-02-24 11:13:16 +13:00
await controller.destroy(ctx)
ctx.body = ctx.table
await next()
2022-02-24 11:13:16 +13:00
}
2022-02-25 04:13:14 +13:00
export default {
create,
read,
update,
destroy,
search,
}