adds update functionality to users
This commit is contained in:
parent
1d9a0b9b0d
commit
1440ed9fdd
|
@ -63,7 +63,23 @@ exports.create = async function(ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
exports.update = async function() {}
|
||||
exports.update = async function (ctx) {
|
||||
const db = new CouchDB(ctx.user.instanceId)
|
||||
const user = ctx.request.body
|
||||
|
||||
const response = await db.put(user)
|
||||
user._rev = response.rev
|
||||
|
||||
ctx.status = 200
|
||||
ctx.body = {
|
||||
message: `User ${ctx.request.body.username} updated successfully.`,
|
||||
user: {
|
||||
...user,
|
||||
_rev: response.rev,
|
||||
_id: response.id,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
exports.destroy = async function (ctx) {
|
||||
const database = new CouchDB(ctx.user.instanceId)
|
||||
|
|
|
@ -8,6 +8,7 @@ const router = Router()
|
|||
router
|
||||
.get("/api/users", authorized(LIST_USERS), controller.fetch)
|
||||
.get("/api/users/:username", authorized(USER_MANAGEMENT), controller.find)
|
||||
.put("/api/users/", authorized(USER_MANAGEMENT), controller.update)
|
||||
.post("/api/users", authorized(USER_MANAGEMENT), controller.create)
|
||||
.delete(
|
||||
"/api/users/:username",
|
||||
|
|
Loading…
Reference in New Issue