]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users.ts
Upgrade common server dependencies
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users.ts
index 845facd55847dd53fc3d99defde794a4f28e0b47..04d8851855774361f562c5365f683478844a60a6 100644 (file)
@@ -2,11 +2,11 @@ import * as express from 'express'
 
 import { database as db } from '../../initializers/database'
 import { USER_ROLES } from '../../initializers'
-import { logger, getFormatedObjects } from '../../helpers'
+import { logger, getFormattedObjects } from '../../helpers'
 import {
   authenticate,
   ensureIsAdmin,
-  ensureUserRegistrationEnabled,
+  ensureUserRegistrationAllowed,
   usersAddValidator,
   usersUpdateValidator,
   usersRemoveValidator,
@@ -17,7 +17,7 @@ import {
   setUsersSort,
   token
 } from '../../middlewares'
-import { UserVideoRate as FormatedUserVideoRate } from '../../../shared'
+import { UserVideoRate as FormattedUserVideoRate, UserCreate, UserUpdate } from '../../../shared'
 
 const usersRouter = express.Router()
 
@@ -48,7 +48,7 @@ usersRouter.post('/',
 )
 
 usersRouter.post('/register',
-  ensureUserRegistrationEnabled,
+  ensureUserRegistrationAllowed,
   usersAddValidator,
   createUser
 )
@@ -78,10 +78,12 @@ export {
 // ---------------------------------------------------------------------------
 
 function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const body: UserCreate = req.body
+
   const user = db.User.build({
-    username: req.body.username,
-    password: req.body.password,
-    email: req.body.email,
+    username: body.username,
+    password: body.password,
+    email: body.email,
     displayNSFW: false,
     role: USER_ROLES.USER
   })
@@ -93,18 +95,18 @@ function createUser (req: express.Request, res: express.Response, next: express.
 
 function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
   db.User.loadByUsername(res.locals.oauth.token.user.username)
-    .then(user => res.json(user.toFormatedJSON()))
+    .then(user => res.json(user.toFormattedJSON()))
     .catch(err => next(err))
 }
 
 function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const videoId = '' + req.params.videoId
+  const videoId = +req.params.videoId
   const userId = +res.locals.oauth.token.User.id
 
   db.UserVideoRate.load(userId, videoId, null)
     .then(ratingObj => {
       const rating = ratingObj ? ratingObj.type : 'none'
-      const json: FormatedUserVideoRate = {
+      const json: FormattedUserVideoRate = {
         videoId,
         rating
       }
@@ -116,7 +118,7 @@ function getUserVideoRating (req: express.Request, res: express.Response, next:
 function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
   db.User.listForApi(req.query.start, req.query.count, req.query.sort)
     .then(resultList => {
-      res.json(getFormatedObjects(resultList.data, resultList.total))
+      res.json(getFormattedObjects(resultList.data, resultList.total))
     })
     .catch(err => next(err))
 }
@@ -132,10 +134,12 @@ function removeUser (req: express.Request, res: express.Response, next: express.
 }
 
 function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const body: UserUpdate = req.body
+
   db.User.loadByUsername(res.locals.oauth.token.user.username)
     .then(user => {
-      if (req.body.password) user.password = req.body.password
-      if (req.body.displayNSFW !== undefined) user.displayNSFW = req.body.displayNSFW
+      if (body.password) user.password = body.password
+      if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW
 
       return user.save()
     })