basic user creation

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

View File

@ -3,11 +3,11 @@ const couchdb = require("../../db");
const controller = { const controller = {
fetch: async ctx => { fetch: async ctx => {
const database = couchdb.db.use(ctx.params.databaseId); 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 => { create: async ctx => {
const database = couchdb.db.use(ctx.params.databaseId); 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 => { destroy: async ctx => {
const database = couchdb.db.use(ctx.params.databaseId); const database = couchdb.db.use(ctx.params.databaseId);

View File

@ -17,6 +17,7 @@ const {
const recordRoutes = require("./routes/neo/record"); const recordRoutes = require("./routes/neo/record");
const databaseRoutes = require("./routes/neo/database"); const databaseRoutes = require("./routes/neo/database");
const neoUserRoutes = require("./routes/neo/user");
const builderPath = resolve(__dirname, "../builder") 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.routes());
router.use(recordRoutes.allowedMethods()); router.use(recordRoutes.allowedMethods());
@ -123,6 +127,10 @@ module.exports = (config, app) => {
router.use(databaseRoutes.routes()); router.use(databaseRoutes.routes());
router.use(databaseRoutes.allowedMethods()); router.use(databaseRoutes.allowedMethods());
router.use(databaseRoutes.routes());
router.use(databaseRoutes.allowedMethods());
// end of Neo
router.use(userRoutes.routes()); router.use(userRoutes.routes());
router.use(userRoutes.allowedMethods()); router.use(userRoutes.allowedMethods());
router.use(appsRoutes.routes()) router.use(appsRoutes.routes())

View File

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