From 00443d9dd655298ea194993a71d97368e356cab7 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 7 Apr 2020 17:38:01 +0100 Subject: [PATCH] basic user creation --- packages/server/middleware/controllers/user.js | 4 ++-- packages/server/middleware/routers.js | 8 ++++++++ packages/server/middleware/routes/neo/user.js | 6 ------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/server/middleware/controllers/user.js b/packages/server/middleware/controllers/user.js index 4d1066635d..b1b1e04a77 100644 --- a/packages/server/middleware/controllers/user.js +++ b/packages/server/middleware/controllers/user.js @@ -3,11 +3,11 @@ const couchdb = require("../../db"); const controller = { fetch: async ctx => { const database = couchdb.db.use(ctx.params.databaseId); - ctx.body = await database.list({ type: "user" }); + ctx.body = await database.list({ include_docs: true }); }, create: async ctx => { const database = couchdb.db.use(ctx.params.databaseId); - ctx.body = await database.create(ctx.request.body.user); + ctx.body = await database.insert(ctx.request.body); }, destroy: async ctx => { const database = couchdb.db.use(ctx.params.databaseId); diff --git a/packages/server/middleware/routers.js b/packages/server/middleware/routers.js index 9d64a09812..0e45aa1b37 100644 --- a/packages/server/middleware/routers.js +++ b/packages/server/middleware/routers.js @@ -17,6 +17,7 @@ const { const recordRoutes = require("./routes/neo/record"); const databaseRoutes = require("./routes/neo/database"); +const neoUserRoutes = require("./routes/neo/user"); const builderPath = resolve(__dirname, "../builder") @@ -116,6 +117,9 @@ module.exports = (config, app) => { } }) + // Neo + router.use(neoUserRoutes.routes()); + router.use(neoUserRoutes.allowedMethods()); router.use(recordRoutes.routes()); router.use(recordRoutes.allowedMethods()); @@ -123,6 +127,10 @@ module.exports = (config, app) => { router.use(databaseRoutes.routes()); router.use(databaseRoutes.allowedMethods()); + router.use(databaseRoutes.routes()); + router.use(databaseRoutes.allowedMethods()); + // end of Neo + router.use(userRoutes.routes()); router.use(userRoutes.allowedMethods()); router.use(appsRoutes.routes()) diff --git a/packages/server/middleware/routes/neo/user.js b/packages/server/middleware/routes/neo/user.js index 3117a2f3ed..a398a22d37 100644 --- a/packages/server/middleware/routes/neo/user.js +++ b/packages/server/middleware/routes/neo/user.js @@ -1,15 +1,9 @@ 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);