added more endpoints
This commit is contained in:
parent
514998648a
commit
04869c6b5a
|
@ -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;
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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/*",
|
||||
|
|
|
@ -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)
|
|
@ -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;
|
Loading…
Reference in New Issue