forked from tsai/budibase
19 changed files with 237 additions and 135 deletions
@ -1,14 +0,0 @@ |
|||||
const { search } = require("./utils") |
|
||||
const queryController = require("../query") |
|
||||
|
|
||||
exports.search = async ctx => { |
|
||||
await queryController.fetch(ctx) |
|
||||
const { name } = ctx.request.body |
|
||||
ctx.body = { |
|
||||
queries: search(ctx.body, name), |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
exports.execute = async ctx => { |
|
||||
await queryController.executeV2(ctx) |
|
||||
} |
|
||||
@ -0,0 +1,19 @@ |
|||||
|
import { search as stringSearch } from "./utils" |
||||
|
import { default as queryController } from "../query" |
||||
|
|
||||
|
export async function search(ctx: any) { |
||||
|
await queryController.fetch(ctx) |
||||
|
const { name } = ctx.request.body |
||||
|
ctx.body = { |
||||
|
queries: stringSearch(ctx.body, name), |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export async function execute(ctx: any) { |
||||
|
await queryController.executeV2(ctx) |
||||
|
} |
||||
|
|
||||
|
export default { |
||||
|
search, |
||||
|
execute, |
||||
|
} |
||||
@ -1,31 +1,39 @@ |
|||||
const { search, addRev } = require("./utils") |
import { search as stringSearch, addRev } from "./utils" |
||||
const controller = require("../table") |
import { default as controller } from "../table" |
||||
|
|
||||
exports.search = async ctx => { |
export async function search(ctx: any) { |
||||
const { name } = ctx.request.body |
const { name } = ctx.request.body |
||||
await controller.fetch(ctx) |
await controller.fetch(ctx) |
||||
ctx.body = { |
ctx.body = { |
||||
tables: search(ctx.body, name), |
tables: stringSearch(ctx.body, name), |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
exports.create = async ctx => { |
export async function create(ctx: any) { |
||||
await controller.save(ctx) |
await controller.save(ctx) |
||||
ctx.body = { table: ctx.body } |
ctx.body = { table: ctx.body } |
||||
} |
} |
||||
|
|
||||
exports.read = async ctx => { |
export async function read(ctx: any) { |
||||
await controller.find(ctx) |
await controller.find(ctx) |
||||
ctx.body = { table: ctx.body } |
ctx.body = { table: ctx.body } |
||||
} |
} |
||||
|
|
||||
exports.update = async ctx => { |
export async function update(ctx: any) { |
||||
ctx.request.body = await addRev(ctx.request.body, ctx.params.tableId) |
ctx.request.body = await addRev(ctx.request.body, ctx.params.tableId) |
||||
await controller.save(ctx) |
await controller.save(ctx) |
||||
ctx.body = { table: ctx.body } |
ctx.body = { table: ctx.body } |
||||
} |
} |
||||
|
|
||||
exports.delete = async ctx => { |
export async function destroy(ctx: any) { |
||||
await controller.destroy(ctx) |
await controller.destroy(ctx) |
||||
ctx.body = { table: ctx.table } |
ctx.body = { table: ctx.table } |
||||
} |
} |
||||
|
|
||||
|
export default { |
||||
|
create, |
||||
|
read, |
||||
|
update, |
||||
|
destroy, |
||||
|
search, |
||||
|
} |
||||
@ -1,9 +0,0 @@ |
|||||
exports.search = () => {} |
|
||||
|
|
||||
exports.create = () => {} |
|
||||
|
|
||||
exports.read = () => {} |
|
||||
|
|
||||
exports.update = () => {} |
|
||||
|
|
||||
exports.delete = () => {} |
|
||||
@ -0,0 +1,17 @@ |
|||||
|
export async function search() {} |
||||
|
|
||||
|
export async function create() {} |
||||
|
|
||||
|
export async function read() {} |
||||
|
|
||||
|
export async function update() {} |
||||
|
|
||||
|
export async function destroy() {} |
||||
|
|
||||
|
export default { |
||||
|
create, |
||||
|
read, |
||||
|
update, |
||||
|
destroy, |
||||
|
search, |
||||
|
} |
||||
@ -1,24 +1,34 @@ |
|||||
|
import Router from "koa-router" |
||||
|
|
||||
|
export type CtxFn = (ctx: any) => void |
||||
|
|
||||
class Endpoint { |
class Endpoint { |
||||
constructor(method, url, controller) { |
method: string |
||||
|
url: string |
||||
|
controller: CtxFn |
||||
|
middlewares: CtxFn[] |
||||
|
|
||||
|
constructor(method: string, url: string, controller: CtxFn) { |
||||
this.method = method |
this.method = method |
||||
this.url = url |
this.url = url |
||||
this.controller = controller |
this.controller = controller |
||||
this.middlewares = [] |
this.middlewares = [] |
||||
} |
} |
||||
|
|
||||
addMiddleware(middleware) { |
addMiddleware(middleware: CtxFn) { |
||||
this.middlewares.push(middleware) |
this.middlewares.push(middleware) |
||||
return this |
return this |
||||
} |
} |
||||
|
|
||||
apply(router) { |
apply(router: Router) { |
||||
const method = this.method, |
const method = this.method, |
||||
url = this.url |
url = this.url |
||||
const middlewares = this.middlewares, |
const middlewares = this.middlewares, |
||||
controller = this.controller |
controller = this.controller |
||||
const params = [url, ...middlewares, controller] |
const params = [url, ...middlewares, controller] |
||||
|
// @ts-ignore
|
||||
router[method](...params) |
router[method](...params) |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
module.exports = Endpoint |
export default Endpoint |
||||
Loading…
Reference in new issue