Adding a get self endpoint in the global users.
This commit is contained in:
parent
5e7ca07af7
commit
91ed6679c4
|
@ -48,7 +48,7 @@ exports.updateMetadata = async function (ctx) {
|
||||||
const appId = ctx.appId
|
const appId = ctx.appId
|
||||||
const db = new CouchDB(appId)
|
const db = new CouchDB(appId)
|
||||||
const user = ctx.request.body
|
const user = ctx.request.body
|
||||||
// make sure to always remove global user props
|
// make sure to always remove some of the global user props
|
||||||
delete user.password
|
delete user.password
|
||||||
delete user.roles
|
delete user.roles
|
||||||
delete user.builder
|
delete user.builder
|
||||||
|
|
|
@ -96,7 +96,15 @@ exports.destroy = async ctx => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.self = async ctx => {
|
exports.getSelf = async ctx => {
|
||||||
|
ctx.params = {
|
||||||
|
id: ctx.user._id
|
||||||
|
}
|
||||||
|
// this will set the body
|
||||||
|
await exports.find(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.updateSelf = async ctx => {
|
||||||
const db = new CouchDB(GLOBAL_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
const user = await db.get(ctx.user._id)
|
const user = await db.get(ctx.user._id)
|
||||||
if (ctx.request.body.password) {
|
if (ctx.request.body.password) {
|
||||||
|
|
|
@ -60,7 +60,8 @@ router
|
||||||
.post("/api/admin/users", buildUserSaveValidation(), controller.save)
|
.post("/api/admin/users", buildUserSaveValidation(), controller.save)
|
||||||
.get("/api/admin/users", controller.fetch)
|
.get("/api/admin/users", controller.fetch)
|
||||||
.post("/api/admin/users/init", controller.adminUser)
|
.post("/api/admin/users/init", controller.adminUser)
|
||||||
.post("/api/admin/users/self", buildUserSaveValidation(true), controller.self)
|
.get("/api/admin/users/self", controller.getSelf)
|
||||||
|
.post("/api/admin/users/self", buildUserSaveValidation(true), controller.updateSelf)
|
||||||
.delete("/api/admin/users/:id", controller.destroy)
|
.delete("/api/admin/users/:id", controller.destroy)
|
||||||
.get("/api/admin/users/:id", controller.find)
|
.get("/api/admin/users/:id", controller.find)
|
||||||
.get("/api/admin/roles/:appId")
|
.get("/api/admin/roles/:appId")
|
||||||
|
|
Loading…
Reference in New Issue