diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-10 19:43:21 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-10 19:43:21 +0200 |
commit | 4771e0008dd26eadbb7eaff64255a6ec914fdadb (patch) | |
tree | 4fd58f8a3f3c2d674b936c99817b4f5fb958c5d8 /server/controllers/api/users.ts | |
parent | 7a214f746bf420defbf17fa218d90d6233551bf8 (diff) | |
download | PeerTube-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.ts | 16 |
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' |
20 | import { UserVideoRate as FormatedUserVideoRate } from '../../../shared' | 20 | import { UserVideoRate as FormatedUserVideoRate, UserCreate, UserUpdate } from '../../../shared' |
21 | 21 | ||
22 | const usersRouter = express.Router() | 22 | const usersRouter = express.Router() |
23 | 23 | ||
@@ -78,10 +78,12 @@ export { | |||
78 | // --------------------------------------------------------------------------- | 78 | // --------------------------------------------------------------------------- |
79 | 79 | ||
80 | function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 80 | function 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 | ||
134 | function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 136 | function 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 | }) |