aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/controllers/api/users.ts
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts28
1 files changed, 15 insertions, 13 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index f9b871724..d6c0e67f9 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared' 2import { UserCreate, UserRight, UserRole, UserUpdate, UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../shared'
3import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers' 3import { getFormattedObjects, logger, retryTransactionWrapper } from '../../helpers'
4import { CONFIG, database as db } from '../../initializers' 4import { CONFIG } from '../../initializers'
5import { createUserAccountAndChannel } from '../../lib' 5import { createUserAccountAndChannel } from '../../lib'
6import { 6import {
7 asyncMiddleware, 7 asyncMiddleware,
@@ -11,6 +11,7 @@ import {
11 paginationValidator, 11 paginationValidator,
12 setPagination, 12 setPagination,
13 setUsersSort, 13 setUsersSort,
14 setVideosSort,
14 token, 15 token,
15 usersAddValidator, 16 usersAddValidator,
16 usersGetValidator, 17 usersGetValidator,
@@ -21,9 +22,10 @@ import {
21 usersUpdateValidator, 22 usersUpdateValidator,
22 usersVideoRatingValidator 23 usersVideoRatingValidator
23} from '../../middlewares' 24} from '../../middlewares'
24import { setVideosSort } from '../../middlewares/sort' 25import { videosSortValidator } from '../../middlewares/validators'
25import { videosSortValidator } from '../../middlewares/validators/sort' 26import { AccountVideoRateModel } from '../../models/account/account-video-rate'
26import { UserInstance } from '../../models' 27import { UserModel } from '../../models/account/user'
28import { VideoModel } from '../../models/video/video'
27 29
28const usersRouter = express.Router() 30const usersRouter = express.Router()
29 31
@@ -107,8 +109,8 @@ export {
107// --------------------------------------------------------------------------- 109// ---------------------------------------------------------------------------
108 110
109async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 111async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
110 const user = res.locals.oauth.token.User 112 const user = res.locals.oauth.token.User as UserModel
111 const resultList = await db.Video.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort) 113 const resultList = await VideoModel.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort)
112 114
113 return res.json(getFormattedObjects(resultList.data, resultList.total)) 115 return res.json(getFormattedObjects(resultList.data, resultList.total))
114} 116}
@@ -127,7 +129,7 @@ async function createUserRetryWrapper (req: express.Request, res: express.Respon
127 129
128async function createUser (req: express.Request) { 130async function createUser (req: express.Request) {
129 const body: UserCreate = req.body 131 const body: UserCreate = req.body
130 const user = db.User.build({ 132 const user = new UserModel({
131 username: body.username, 133 username: body.username,
132 password: body.password, 134 password: body.password,
133 email: body.email, 135 email: body.email,
@@ -155,7 +157,7 @@ async function registerUserRetryWrapper (req: express.Request, res: express.Resp
155async function registerUser (req: express.Request) { 157async function registerUser (req: express.Request) {
156 const body: UserCreate = req.body 158 const body: UserCreate = req.body
157 159
158 const user = db.User.build({ 160 const user = new UserModel({
159 username: body.username, 161 username: body.username,
160 password: body.password, 162 password: body.password,
161 email: body.email, 163 email: body.email,
@@ -171,7 +173,7 @@ async function registerUser (req: express.Request) {
171 173
172async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { 174async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
173 // We did not load channels in res.locals.user 175 // We did not load channels in res.locals.user
174 const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) 176 const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
175 177
176 return res.json(user.toFormattedJSON()) 178 return res.json(user.toFormattedJSON())
177} 179}
@@ -184,7 +186,7 @@ async function getUserVideoRating (req: express.Request, res: express.Response,
184 const videoId = +req.params.videoId 186 const videoId = +req.params.videoId
185 const accountId = +res.locals.oauth.token.User.Account.id 187 const accountId = +res.locals.oauth.token.User.Account.id
186 188
187 const ratingObj = await db.AccountVideoRate.load(accountId, videoId, null) 189 const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null)
188 const rating = ratingObj ? ratingObj.type : 'none' 190 const rating = ratingObj ? ratingObj.type : 'none'
189 191
190 const json: FormattedUserVideoRate = { 192 const json: FormattedUserVideoRate = {
@@ -195,13 +197,13 @@ async function getUserVideoRating (req: express.Request, res: express.Response,
195} 197}
196 198
197async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { 199async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
198 const resultList = await db.User.listForApi(req.query.start, req.query.count, req.query.sort) 200 const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort)
199 201
200 return res.json(getFormattedObjects(resultList.data, resultList.total)) 202 return res.json(getFormattedObjects(resultList.data, resultList.total))
201} 203}
202 204
203async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) { 205async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) {
204 const user = await db.User.loadById(req.params.id) 206 const user = await UserModel.loadById(req.params.id)
205 207
206 await user.destroy() 208 await user.destroy()
207 209
@@ -225,7 +227,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr
225 227
226async function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { 228async function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
227 const body: UserUpdate = req.body 229 const body: UserUpdate = req.body
228 const user: UserInstance = res.locals.user 230 const user = res.locals.user as UserModel
229 231
230 if (body.email !== undefined) user.email = body.email 232 if (body.email !== undefined) user.email = body.email
231 if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota 233 if (body.videoQuota !== undefined) user.videoQuota = body.videoQuota