1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Better typescript typing for a better world

This commit is contained in:
Chocobozzz 2017-07-10 19:43:21 +02:00
parent 7a214f746b
commit 4771e0008d
59 changed files with 400 additions and 166 deletions

View file

@ -17,7 +17,7 @@ import {
setUsersSort,
token
} from '../../middlewares'
import { UserVideoRate as FormatedUserVideoRate } from '../../../shared'
import { UserVideoRate as FormatedUserVideoRate, UserCreate, UserUpdate } from '../../../shared'
const usersRouter = express.Router()
@ -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
})
@ -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()
})