Skip to content
Snippets Groups Projects
Commit c4766c54 authored by Louis's avatar Louis :fire:
Browse files

Add single property update to self object

parent 5390d3f0
No related branches found
No related tags found
No related merge requests found
const HttpError = require('core/errors/HttpError')
exports.self = async ctx => {
const user = await ctx.services.authService.getUser()
if (user) {
......@@ -13,5 +15,21 @@ exports.updateSelf = async ctx => {
await user.handleIncludes(ctx.includes)
}
ctx.body = { user }
}
exports.updateOne = async ctx => {
const user = await ctx.services.authService.getUser()
if (user) {
const { property } = ctx.params
const { value } = ctx.request.body
user[property] = value
await user.save()
await user.handleIncludes(ctx.includes)
} else {
throw new HttpError({ status: 404, title: 'No such user', description: 'No user is currently logged in' })
}
ctx.body = { user }
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ api.post('/register', controller('api/auth', 'register'))
api.post('/login', controller('api/auth', 'login'))
api.get('/self', controller('api/user', 'self'))
api.put('/self/:property', controller('api/user', 'updateOne'))
module.exports = {
api,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment