basic user creation

This commit is contained in:
Martin McKeaveney 2020-04-07 17:38:01 +01:00
parent 2d75127706
commit 00443d9dd6
3 changed files with 10 additions and 8 deletions

View File

@ -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);

View File

@ -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())

View File

@ -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);