fetch users from couch, create design document on DB creation
This commit is contained in:
parent
1341f6cbcf
commit
6b77b2825f
|
@ -1,6 +1,10 @@
|
|||
const couchdb = require("../../db");
|
||||
|
||||
const controller = {
|
||||
fetch: async ctx => {
|
||||
const clientDatabase = couchdb.db.use(ctx.params.clientId);
|
||||
ctx.body = await clientDatabase.list({ type: "app" });
|
||||
},
|
||||
create: async ctx => {
|
||||
const clientDatabase = couchdb.db.use(ctx.params.clientId);
|
||||
ctx.body = await clientDatabase.insert(ctx.request.body);
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
const couchdb = require("../../db");
|
||||
|
||||
const controller = {
|
||||
save: async ctx => {
|
||||
},
|
||||
fetch: async ctx => {
|
||||
const databaseId = ctx.params.databaseId;
|
||||
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);
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = controller;
|
|
@ -1,8 +1,25 @@
|
|||
const couchdb = require("../../db");
|
||||
|
||||
const controller = {
|
||||
fetch: async ctx => {
|
||||
|
||||
},
|
||||
create: async ctx => {
|
||||
ctx.body = await couchdb.db.create(ctx.request.body.databaseName);
|
||||
const databaseName = ctx.request.body.databaseName;
|
||||
await couchdb.db.create(databaseName);
|
||||
const db = couchdb.db.use(databaseName)
|
||||
await db.insert({
|
||||
views: {
|
||||
by_type: {
|
||||
map: function(doc) {
|
||||
emit([doc.type], doc._id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, '_design/database');
|
||||
ctx.body = {
|
||||
message: `Database ${databaseName} successfully provisioned.`
|
||||
}
|
||||
},
|
||||
destroy: async ctx => {
|
||||
ctx.body = await couchdb.db.destroy(ctx.params.databaseName)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
const couchdb = require("../../db");
|
||||
const fs = require("fs");
|
||||
|
||||
const controller = {
|
||||
download: async ctx => {
|
||||
// const appDatabase = couchdb.db.use(ctx.params.appId)
|
||||
// appDatabase.attachment.get('rabbit', 'rabbit.png', function(err, body) {
|
||||
// if (!err) {
|
||||
// fs.writeFile('rabbit.png', body);
|
||||
// }
|
||||
// });
|
||||
},
|
||||
upload: async ctx => {
|
||||
// const appDatabase = couchdb.db.use(ctx.params.appId)
|
||||
// fs.readFile('rabbit.png', function(err, data) {
|
||||
// if (!err) {
|
||||
// alice.attachment.insert('rabbit', 'rabbit.png', data, 'image/png',
|
||||
// { rev: '12-150985a725ec88be471921a54ce91452' }, function(err, body) {
|
||||
// if (!err)
|
||||
// console.log(body);
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = controller;
|
|
@ -3,7 +3,10 @@ const couchdb = require("../../db");
|
|||
const controller = {
|
||||
fetch: async ctx => {
|
||||
const database = couchdb.db.use(ctx.params.databaseId);
|
||||
ctx.body = await database.list({ include_docs: true });
|
||||
ctx.body = await database.view("database", "by_type", {
|
||||
include_docs: true,
|
||||
key: ["user"]
|
||||
})
|
||||
},
|
||||
create: async ctx => {
|
||||
const database = couchdb.db.use(ctx.params.databaseId);
|
||||
|
|
|
@ -3,6 +3,8 @@ const controller = require("../../controllers/application");
|
|||
|
||||
const router = Router();
|
||||
|
||||
router.post("/api/:clientId/applications", controller.create)
|
||||
router
|
||||
.get("/api/:clientId/applications", controller.fetch)
|
||||
.post("/api/:clientId/applications", controller.create)
|
||||
|
||||
module.exports = router;
|
|
@ -0,0 +1,10 @@
|
|||
const Router = require("@koa/router");
|
||||
const controller = require("../../controllers/client");
|
||||
|
||||
const router = Router();
|
||||
|
||||
router
|
||||
.post("/api/clients", controller.create)
|
||||
.delete("/api/clients/:clientId", controller.destroy);
|
||||
|
||||
module.exports = router;
|
|
@ -4,6 +4,7 @@ const controller = require("../../controllers/database");
|
|||
const router = Router();
|
||||
|
||||
router
|
||||
.get("/api/databases", controller.fetch)
|
||||
.post("/api/databases", controller.create)
|
||||
.delete("/api/databases/:databaseId", controller.destroy);
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
const Router = require("@koa/router");
|
||||
const controller = require("../../controllers/view");
|
||||
|
||||
const router = Router();
|
||||
|
||||
router
|
||||
.get("/api/:databaseId/views", controller.fetch)
|
||||
.post("/api/:databaseId/views", controller.create)
|
||||
.patch("/api/:databaseId/views", controller.update);
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in New Issue