2020-06-13 07:42:55 +12:00
|
|
|
const Router = require("@koa/router")
|
|
|
|
const recordController = require("../controllers/record")
|
|
|
|
const authorized = require("../../middleware/authorized")
|
2020-10-07 07:13:41 +13:00
|
|
|
const usage = require("../../middleware/usageQuota")
|
2020-10-10 06:49:23 +13:00
|
|
|
const { READ_TABLE, WRITE_TABLE } = require("../../utilities/accessLevels")
|
2020-06-13 07:42:55 +12:00
|
|
|
|
|
|
|
const router = Router()
|
|
|
|
|
|
|
|
router
|
2020-09-30 00:02:06 +13:00
|
|
|
.get(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/:recordId/enrich",
|
|
|
|
authorized(READ_TABLE, ctx => ctx.params.tableId),
|
2020-10-01 03:37:38 +13:00
|
|
|
recordController.fetchEnrichedRecord
|
2020-09-30 00:02:06 +13:00
|
|
|
)
|
2020-06-13 07:42:55 +12:00
|
|
|
.get(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/records",
|
|
|
|
authorized(READ_TABLE, ctx => ctx.params.tableId),
|
|
|
|
recordController.fetchTableRecords
|
2020-06-13 07:42:55 +12:00
|
|
|
)
|
|
|
|
.get(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/records/:recordId",
|
|
|
|
authorized(READ_TABLE, ctx => ctx.params.tableId),
|
2020-06-13 07:42:55 +12:00
|
|
|
recordController.find
|
|
|
|
)
|
2020-06-19 03:59:31 +12:00
|
|
|
.post("/api/records/search", recordController.search)
|
2020-06-13 07:42:55 +12:00
|
|
|
.post(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/records",
|
|
|
|
authorized(WRITE_TABLE, ctx => ctx.params.tableId),
|
2020-10-07 07:13:41 +13:00
|
|
|
usage,
|
2020-06-13 07:42:55 +12:00
|
|
|
recordController.save
|
|
|
|
)
|
2020-09-10 20:36:14 +12:00
|
|
|
.patch(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/records/:id",
|
|
|
|
authorized(WRITE_TABLE, ctx => ctx.params.tableId),
|
2020-09-11 08:11:05 +12:00
|
|
|
recordController.patch
|
2020-09-10 20:36:14 +12:00
|
|
|
)
|
2020-06-13 07:42:55 +12:00
|
|
|
.post(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/records/validate",
|
|
|
|
authorized(WRITE_TABLE, ctx => ctx.params.tableId),
|
2020-06-13 07:42:55 +12:00
|
|
|
recordController.validate
|
|
|
|
)
|
|
|
|
.delete(
|
2020-10-10 06:49:23 +13:00
|
|
|
"/api/:tableId/records/:recordId/:revId",
|
|
|
|
authorized(WRITE_TABLE, ctx => ctx.params.tableId),
|
2020-10-07 07:13:41 +13:00
|
|
|
usage,
|
2020-06-13 07:42:55 +12:00
|
|
|
recordController.destroy
|
|
|
|
)
|
|
|
|
|
|
|
|
module.exports = router
|