aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-10 19:43:21 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-10 19:43:21 +0200
commit4771e0008dd26eadbb7eaff64255a6ec914fdadb (patch)
tree4fd58f8a3f3c2d674b936c99817b4f5fb958c5d8 /server/controllers/api/users.ts
parent7a214f746bf420defbf17fa218d90d6233551bf8 (diff)
downloadPeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.gz
PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.zst
PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.zip
Better typescript typing for a better world
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts16
1 files changed, 10 insertions, 6 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 845facd55..e79480521 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -17,7 +17,7 @@ import {
17 setUsersSort, 17 setUsersSort,
18 token 18 token
19} from '../../middlewares' 19} from '../../middlewares'
20import { UserVideoRate as FormatedUserVideoRate } from '../../../shared' 20import { UserVideoRate as FormatedUserVideoRate, UserCreate, UserUpdate } from '../../../shared'
21 21
22const usersRouter = express.Router() 22const usersRouter = express.Router()
23 23
@@ -78,10 +78,12 @@ export {
78// --------------------------------------------------------------------------- 78// ---------------------------------------------------------------------------
79 79
80function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { 80function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
81 const body: UserCreate = req.body
82
81 const user = db.User.build({ 83 const user = db.User.build({
82 username: req.body.username, 84 username: body.username,
83 password: req.body.password, 85 password: body.password,
84 email: req.body.email, 86 email: body.email,
85 displayNSFW: false, 87 displayNSFW: false,
86 role: USER_ROLES.USER 88 role: USER_ROLES.USER
87 }) 89 })
@@ -132,10 +134,12 @@ function removeUser (req: express.Request, res: express.Response, next: express.
132} 134}
133 135
134function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { 136function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
137 const body: UserUpdate = req.body
138
135 db.User.loadByUsername(res.locals.oauth.token.user.username) 139 db.User.loadByUsername(res.locals.oauth.token.user.username)
136 .then(user => { 140 .then(user => {
137 if (req.body.password) user.password = req.body.password 141 if (body.password) user.password = body.password
138 if (req.body.displayNSFW !== undefined) user.displayNSFW = req.body.displayNSFW 142 if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW
139 143
140 return user.save() 144 return user.save()
141 }) 145 })