Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Jetsam Server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jetsam
Jetsam Server
Commits
c4766c54
Commit
c4766c54
authored
5 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Add single property update to self object
parent
5390d3f0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/http/controllers/api/user.js
+18
-0
18 additions, 0 deletions
src/http/controllers/api/user.js
src/http/routes.js
+1
-0
1 addition, 0 deletions
src/http/routes.js
with
19 additions
and
0 deletions
src/http/controllers/api/user.js
+
18
−
0
View file @
c4766c54
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
This diff is collapsed.
Click to expand it.
src/http/routes.js
+
1
−
0
View file @
c4766c54
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment