added more endpoints

This commit is contained in:
Martin McKeaveney 2020-04-07 17:25:09 +01:00
parent 514998648a
commit 04869c6b5a
11 changed files with 76 additions and 20 deletions

View File

@ -0,0 +1,9 @@
const couchdb = require("../../db");
const controller = {
create: async ctx => {
ctx.body = await couchdb.db.create(ctx.request.body.appName);
}
}
module.exports = controller;

View File

@ -5,7 +5,7 @@ const controller = {
ctx.body = await couchdb.db.create(ctx.request.body.databaseName);
},
destroy: async ctx => {
ctx.body = await couchdb.db.destroy(ctx.request.body.databaseName)
ctx.body = await couchdb.db.destroy(ctx.params.databaseName)
}
}

View File

@ -5,13 +5,13 @@ const controller = {
},
fetch: async ctx => {
const databaseId = ctx.params.databaseId;
const instance = couchdb.db.use(databaseId)
const documents = await instance.list({});
ctx.status = 200;
ctx.body = documents;
const database = couchdb.db.use(databaseId)
ctx.body = await database.list({});
},
destroy: async ctx => {
const databaseId = ctx.params.databaseId;
const database = couchdb.db.use(databaseId)
ctx.body = await database.destroy(ctx.params.recordId);
},
}

View File

@ -0,0 +1,11 @@
const couchdb = require("../../db");
const controller = {
create: async ctx => {
const appDatabase = couchdb.db.use(ctx.params.appId)
ctx.body = await appDatabase.insert(ctx.request.body);
},
apply: async ctx => {}
}
module.exports = controller;

View File

@ -0,0 +1,18 @@
const couchdb = require("../../db");
const controller = {
fetch: async ctx => {
const database = couchdb.db.use(ctx.params.databaseId);
ctx.body = await database.list({ type: "user" });
},
create: async ctx => {
const database = couchdb.db.use(ctx.params.databaseId);
ctx.body = await database.create(ctx.request.body.user);
},
destroy: async ctx => {
const database = couchdb.db.use(ctx.params.databaseId);
ctx.body = await database.destroy(ctx.params.userId)
}
}
module.exports = controller;

View File

@ -0,0 +1,8 @@
const Router = require("@koa/router");
const controller = require("../../controllers/application");
const router = Router();
router.post("/api/applications/:clientId", controller.create)
module.exports = router;

View File

@ -1,10 +1,10 @@
const Router = require("@koa/router");
const controller = require("../../controllers/database");
const router = Router();
router
.post("/api/databases", controller.create)
.delete("/api/databases", controller.destroy);
.delete("/api/databases/:databaseId", controller.destroy);
module.exports = router;

View File

@ -1,7 +1,4 @@
const Router = require("@koa/router");
// const StatusCodes = require("../../utilities/statusCodes")
// const routeHandlers = require("../routeHandlers")
const controller = require("../../controllers/record");
const router = Router();
@ -9,7 +6,7 @@ const router = Router();
router
.get("/api/records/:databaseId", controller.fetch)
.post("/api/records/:databaseId", controller.save)
.delete("/api/records/:databaseId", controller.destroy)
.delete("/api/records/:databaseId/:recordId", controller.destroy)
// router.post(
// "/_builder/instance/:appname/:instanceid/api/record/*",

View File

@ -1,13 +1,9 @@
const Router = require("@koa/router");
const StatusCodes = require("../../utilities/statusCodes")
const routeHandlers = require("../routeHandlers")
const controller = require("../../controllers/schema");
const router = Router();
router.get("api/schema/:appId", controller.fetch);
router.post("api/schema/:appId", controller.save)
router.delete("api/schema/:appId", controller.delete)
router
.get("/api/schemas/:appId", controller.fetch)
.post("/api/schemas/:appId", controller.save)
.delete("/api/schemas/:appId", controller.delete)

View File

@ -0,0 +1,17 @@
const Router = require("@koa/router");
const controller = require("../../controllers/user");
const couchdb = require("../../db");
const router = Router();
function setDatabase(ctx) {
ctx.database = couchdb.db.use(ctx.params.databaseId);
}
router
.use(setDatabase)
.get("/api/:databaseId/users", controller.fetch)
.post("/api/:databaseId/users", controller.create)
.delete("/api/:databaseId/users/:userId", controller.destroy);
module.exports = router;