From dae86118ed5d4026d04acb9d0e36829b9ad8eb4e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 10:35:15 +0100 Subject: Cleanup express locals typings --- server/controllers/api/users/index.ts | 30 +++++++++++----------- server/controllers/api/users/me.ts | 20 +++++++-------- server/controllers/api/users/my-blocklist.ts | 17 ++++++------ server/controllers/api/users/my-history.ts | 4 +-- server/controllers/api/users/my-notifications.ts | 11 ++++---- server/controllers/api/users/my-subscriptions.ts | 15 +++++------ server/controllers/api/users/my-video-playlists.ts | 3 +-- 7 files changed, 48 insertions(+), 52 deletions(-) (limited to 'server/controllers/api/users') diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index f7edbddf3..2117bdfeb 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -221,8 +221,8 @@ async function registerUser (req: express.Request, res: express.Response) { return res.type('json').status(204).end() } -async function unblockUser (req: express.Request, res: express.Response, next: express.NextFunction) { - const user: UserModel = res.locals.user +async function unblockUser (req: express.Request, res: express.Response) { + const user = res.locals.user await changeUserBlock(res, user, false) @@ -230,7 +230,7 @@ async function unblockUser (req: express.Request, res: express.Response, next: e } async function blockUser (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.user + const user = res.locals.user const reason = req.body.reason await changeUserBlock(res, user, true, reason) @@ -239,7 +239,7 @@ async function blockUser (req: express.Request, res: express.Response) { } function getUser (req: express.Request, res: express.Response) { - return res.json((res.locals.user as UserModel).toFormattedJSON()) + return res.json(res.locals.user.toFormattedJSON()) } async function autocompleteUsers (req: express.Request, res: express.Response) { @@ -255,7 +255,7 @@ async function listUsers (req: express.Request, res: express.Response) { } async function removeUser (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.user + const user = res.locals.user await user.destroy() @@ -266,7 +266,7 @@ async function removeUser (req: express.Request, res: express.Response) { async function updateUser (req: express.Request, res: express.Response) { const body: UserUpdate = req.body - const userToUpdate = res.locals.user as UserModel + const userToUpdate = res.locals.user const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) const roleChanged = body.role !== undefined && body.role !== userToUpdate.role @@ -289,8 +289,8 @@ async function updateUser (req: express.Request, res: express.Response) { return res.sendStatus(204) } -async function askResetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.user as UserModel +async function askResetUserPassword (req: express.Request, res: express.Response) { + const user = res.locals.user const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString @@ -299,8 +299,8 @@ async function askResetUserPassword (req: express.Request, res: express.Response return res.status(204).end() } -async function resetUserPassword (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.user as UserModel +async function resetUserPassword (req: express.Request, res: express.Response) { + const user = res.locals.user user.password = req.body.password await user.save() @@ -315,16 +315,16 @@ async function sendVerifyUserEmail (user: UserModel) { return } -async function askSendVerifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.user as UserModel +async function askSendVerifyUserEmail (req: express.Request, res: express.Response) { + const user = res.locals.user await sendVerifyUserEmail(user) return res.status(204).end() } -async function verifyUserEmail (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.user as UserModel +async function verifyUserEmail (req: express.Request, res: express.Response) { + const user = res.locals.user user.emailVerified = true await user.save() @@ -332,7 +332,7 @@ async function verifyUserEmail (req: express.Request, res: express.Response, nex return res.status(204).end() } -function success (req: express.Request, res: express.Response, next: express.NextFunction) { +function success (req: express.Request, res: express.Response) { res.end() } diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index d5e154869..3533499be 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -93,8 +93,8 @@ export { // --------------------------------------------------------------------------- -async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.oauth.token.User as UserModel +async function getUserVideos (req: express.Request, res: express.Response) { + const user = res.locals.oauth.token.User const resultList = await VideoModel.listUserVideosForApi( user.Account.id, req.query.start as number, @@ -111,8 +111,8 @@ async function getUserVideos (req: express.Request, res: express.Response, next: return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) } -async function getUserVideoImports (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.oauth.token.User as UserModel +async function getUserVideoImports (req: express.Request, res: express.Response) { + const user = res.locals.oauth.token.User const resultList = await VideoImportModel.listUserVideoImportsForApi( user.id, req.query.start as number, @@ -123,14 +123,14 @@ async function getUserVideoImports (req: express.Request, res: express.Response, return res.json(getFormattedObjects(resultList.data, resultList.total)) } -async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getUserInformation (req: express.Request, res: express.Response) { // We did not load channels in res.locals.user const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) return res.json(user.toFormattedJSON()) } -async function getUserVideoQuotaUsed (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) { // We did not load channels in res.locals.user const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user) @@ -143,7 +143,7 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons return res.json(data) } -async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getUserVideoRating (req: express.Request, res: express.Response) { const videoId = res.locals.video.id const accountId = +res.locals.oauth.token.User.Account.id @@ -158,7 +158,7 @@ async function getUserVideoRating (req: express.Request, res: express.Response, } async function deleteMe (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User await user.destroy() @@ -170,7 +170,7 @@ async function deleteMe (req: express.Request, res: express.Response) { async function updateMe (req: express.Request, res: express.Response) { const body: UserUpdateMe = req.body - const user: UserModel = res.locals.oauth.token.user + const user = res.locals.oauth.token.user const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) if (body.password !== undefined) user.password = body.password @@ -199,7 +199,7 @@ async function updateMe (req: express.Request, res: express.Response) { async function updateMyAvatar (req: express.Request, res: express.Response) { const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] - const user: UserModel = res.locals.oauth.token.user + const user = res.locals.oauth.token.user const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) const userAccount = await AccountModel.load(user.Account.id) diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts index 9575eab46..481e75139 100644 --- a/server/controllers/api/users/my-blocklist.ts +++ b/server/controllers/api/users/my-blocklist.ts @@ -17,7 +17,6 @@ import { serversBlocklistSortValidator, unblockServerByAccountValidator } from '../../../middlewares/validators' -import { UserModel } from '../../../models/account/user' import { AccountModel } from '../../../models/account/account' import { AccountBlocklistModel } from '../../../models/account/account-blocklist' import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' @@ -75,7 +74,7 @@ export { // --------------------------------------------------------------------------- async function listBlockedAccounts (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User const resultList = await AccountBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort) @@ -83,8 +82,8 @@ async function listBlockedAccounts (req: express.Request, res: express.Response) } async function blockAccount (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User - const accountToBlock: AccountModel = res.locals.account + const user = res.locals.oauth.token.User + const accountToBlock = res.locals.account await addAccountInBlocklist(user.Account.id, accountToBlock.id) @@ -92,7 +91,7 @@ async function blockAccount (req: express.Request, res: express.Response) { } async function unblockAccount (req: express.Request, res: express.Response) { - const accountBlock: AccountBlocklistModel = res.locals.accountBlock + const accountBlock = res.locals.accountBlock await removeAccountFromBlocklist(accountBlock) @@ -100,7 +99,7 @@ async function unblockAccount (req: express.Request, res: express.Response) { } async function listBlockedServers (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User const resultList = await ServerBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort) @@ -108,8 +107,8 @@ async function listBlockedServers (req: express.Request, res: express.Response) } async function blockServer (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User - const serverToBlock: ServerModel = res.locals.server + const user = res.locals.oauth.token.User + const serverToBlock = res.locals.server await addServerInBlocklist(user.Account.id, serverToBlock.id) @@ -117,7 +116,7 @@ async function blockServer (req: express.Request, res: express.Response) { } async function unblockServer (req: express.Request, res: express.Response) { - const serverBlock: ServerBlocklistModel = res.locals.serverBlock + const serverBlock = res.locals.serverBlock await removeServerFromBlocklist(serverBlock) diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 6cd782c47..b30d3aec2 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts @@ -36,7 +36,7 @@ export { // --------------------------------------------------------------------------- async function listMyVideosHistory (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count) @@ -44,7 +44,7 @@ async function listMyVideosHistory (req: express.Request, res: express.Response) } async function removeUserHistory (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User const beforeDate = req.body.beforeDate || null await sequelizeTypescript.transaction(t => { diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts index 76cf97587..bbafda5a6 100644 --- a/server/controllers/api/users/my-notifications.ts +++ b/server/controllers/api/users/my-notifications.ts @@ -9,7 +9,6 @@ import { setDefaultSort, userNotificationsSortValidator } from '../../../middlewares' -import { UserModel } from '../../../models/account/user' import { getFormattedObjects } from '../../../helpers/utils' import { UserNotificationModel } from '../../../models/account/user-notification' import { meRouter } from './me' @@ -57,8 +56,8 @@ export { // --------------------------------------------------------------------------- async function updateNotificationSettings (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User - const body = req.body + const user = res.locals.oauth.token.User + const body = req.body as UserNotificationSetting const query = { where: { @@ -84,7 +83,7 @@ async function updateNotificationSettings (req: express.Request, res: express.Re } async function listUserNotifications (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread) @@ -92,7 +91,7 @@ async function listUserNotifications (req: express.Request, res: express.Respons } async function markAsReadUserNotifications (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User await UserNotificationModel.markAsRead(user.id, req.body.ids) @@ -100,7 +99,7 @@ async function markAsReadUserNotifications (req: express.Request, res: express.R } async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + const user = res.locals.oauth.token.User await UserNotificationModel.markAllAsRead(user.id) diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index accca6d52..a173adfd0 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts @@ -14,7 +14,6 @@ import { userSubscriptionGetValidator } from '../../../middlewares' import { areSubscriptionsExistValidator, userSubscriptionsSortValidator, videosSortValidator } from '../../../middlewares/validators' -import { UserModel } from '../../../models/account/user' import { VideoModel } from '../../../models/video/video' import { buildNSFWFilter } from '../../../helpers/express-utils' import { VideoFilter } from '../../../../shared/models/videos/video-query.type' @@ -77,7 +76,7 @@ export { async function areSubscriptionsExist (req: express.Request, res: express.Response) { const uris = req.query.uris as string[] - const user = res.locals.oauth.token.User as UserModel + const user = res.locals.oauth.token.User const handles = uris.map(u => { let [ name, host ] = u.split('@') @@ -107,7 +106,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons } async function addUserSubscription (req: express.Request, res: express.Response) { - const user = res.locals.oauth.token.User as UserModel + const user = res.locals.oauth.token.User const [ name, host ] = req.body.uri.split('@') const payload = { @@ -123,13 +122,13 @@ async function addUserSubscription (req: express.Request, res: express.Response) } function getUserSubscription (req: express.Request, res: express.Response) { - const subscription: ActorFollowModel = res.locals.subscription + const subscription = res.locals.subscription return res.json(subscription.ActorFollowing.VideoChannel.toFormattedJSON()) } async function deleteUserSubscription (req: express.Request, res: express.Response) { - const subscription: ActorFollowModel = res.locals.subscription + const subscription = res.locals.subscription await sequelizeTypescript.transaction(async t => { return subscription.destroy({ transaction: t }) @@ -139,7 +138,7 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon } async function getUserSubscriptions (req: express.Request, res: express.Response) { - const user = res.locals.oauth.token.User as UserModel + const user = res.locals.oauth.token.User const actorId = user.Account.Actor.id const resultList = await ActorFollowModel.listSubscriptionsForApi(actorId, req.query.start, req.query.count, req.query.sort) @@ -147,8 +146,8 @@ async function getUserSubscriptions (req: express.Request, res: express.Response return res.json(getFormattedObjects(resultList.data, resultList.total)) } -async function getUserSubscriptionVideos (req: express.Request, res: express.Response, next: express.NextFunction) { - const user = res.locals.oauth.token.User as UserModel +async function getUserSubscriptionVideos (req: express.Request, res: express.Response) { + const user = res.locals.oauth.token.User const resultList = await VideoModel.listForApi({ start: req.query.start, count: req.query.count, diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts index 42da02bff..15e92f4f3 100644 --- a/server/controllers/api/users/my-video-playlists.ts +++ b/server/controllers/api/users/my-video-playlists.ts @@ -1,6 +1,5 @@ import * as express from 'express' import { asyncMiddleware, authenticate } from '../../../middlewares' -import { UserModel } from '../../../models/account/user' import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' import { VideoPlaylistModel } from '../../../models/video/video-playlist' import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' @@ -23,7 +22,7 @@ export { async function doVideosInPlaylistExist (req: express.Request, res: express.Response) { const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) - const user = res.locals.oauth.token.User as UserModel + const user = res.locals.oauth.token.User const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) -- cgit v1.2.3