aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account-video-rate.ts17
-rw-r--r--server/models/account/account.ts16
-rw-r--r--server/models/account/user-notification.ts23
-rw-r--r--server/models/account/user-video-history.ts2
-rw-r--r--server/models/account/user.ts18
5 files changed, 31 insertions, 45 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index 78a897a65..59f586b54 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -1,16 +1,15 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import { Transaction, Op } from 'sequelize' 2import { FindOptions, Op, Transaction } from 'sequelize'
3import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 3import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
4import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions'
5import { VideoRateType } from '../../../shared/models/videos' 4import { VideoRateType } from '../../../shared/models/videos'
6import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' 5import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants'
7import { VideoModel } from '../video/video' 6import { VideoModel } from '../video/video'
8import { AccountModel } from './account' 7import { AccountModel } from './account'
9import { ActorModel } from '../activitypub/actor' 8import { ActorModel } from '../activitypub/actor'
10import { throwIfNotValid, getSort } from '../utils' 9import { getSort, throwIfNotValid } from '../utils'
11import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
12import { AccountVideoRate } from '../../../shared' 11import { AccountVideoRate } from '../../../shared'
13import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel' 12import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from '../video/video-channel'
14 13
15/* 14/*
16 Account rates per video. 15 Account rates per video.
@@ -40,7 +39,7 @@ import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../vide
40export class AccountVideoRateModel extends Model<AccountVideoRateModel> { 39export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
41 40
42 @AllowNull(false) 41 @AllowNull(false)
43 @Column(DataType.ENUM(values(VIDEO_RATE_TYPES))) 42 @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES)))
44 type: VideoRateType 43 type: VideoRateType
45 44
46 @AllowNull(false) 45 @AllowNull(false)
@@ -79,7 +78,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
79 Account: AccountModel 78 Account: AccountModel
80 79
81 static load (accountId: number, videoId: number, transaction?: Transaction) { 80 static load (accountId: number, videoId: number, transaction?: Transaction) {
82 const options: IFindOptions<AccountVideoRateModel> = { 81 const options: FindOptions = {
83 where: { 82 where: {
84 accountId, 83 accountId,
85 videoId 84 videoId
@@ -97,7 +96,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
97 type?: string, 96 type?: string,
98 accountId: number 97 accountId: number
99 }) { 98 }) {
100 const query: IFindOptions<AccountVideoRateModel> = { 99 const query: FindOptions = {
101 offset: options.start, 100 offset: options.start,
102 limit: options.count, 101 limit: options.count,
103 order: getSort(options.sort), 102 order: getSort(options.sort),
@@ -123,7 +122,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
123 } 122 }
124 123
125 static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) { 124 static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) {
126 const options: IFindOptions<AccountVideoRateModel> = { 125 const options: FindOptions = {
127 where: { 126 where: {
128 videoId, 127 videoId,
129 type: rateType 128 type: rateType
@@ -155,7 +154,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
155 } 154 }
156 155
157 static loadByUrl (url: string, transaction: Transaction) { 156 static loadByUrl (url: string, transaction: Transaction) {
158 const options: IFindOptions<AccountVideoRateModel> = { 157 const options: FindOptions = {
159 where: { 158 where: {
160 url 159 url
161 } 160 }
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 6f425024e..bf2ed0a61 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -1,4 +1,3 @@
1import * as Sequelize from 'sequelize'
2import { 1import {
3 AllowNull, 2 AllowNull,
4 BeforeDestroy, 3 BeforeDestroy,
@@ -28,6 +27,7 @@ import { UserModel } from './user'
28import { AvatarModel } from '../avatar/avatar' 27import { AvatarModel } from '../avatar/avatar'
29import { VideoPlaylistModel } from '../video/video-playlist' 28import { VideoPlaylistModel } from '../video/video-playlist'
30import { WEBSERVER } from '../../initializers/constants' 29import { WEBSERVER } from '../../initializers/constants'
30import { Op, Transaction, WhereOptions } from 'sequelize'
31 31
32export enum ScopeNames { 32export enum ScopeNames {
33 SUMMARY = 'SUMMARY' 33 SUMMARY = 'SUMMARY'
@@ -42,7 +42,7 @@ export enum ScopeNames {
42 ] 42 ]
43}) 43})
44@Scopes({ 44@Scopes({
45 [ ScopeNames.SUMMARY ]: (whereActor?: Sequelize.WhereOptions<ActorModel>) => { 45 [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions) => {
46 return { 46 return {
47 attributes: [ 'id', 'name' ], 47 attributes: [ 'id', 'name' ],
48 include: [ 48 include: [
@@ -90,7 +90,7 @@ export class AccountModel extends Model<AccountModel> {
90 90
91 @AllowNull(true) 91 @AllowNull(true)
92 @Default(null) 92 @Default(null)
93 @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description')) 93 @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description', true))
94 @Column 94 @Column
95 description: string 95 description: string
96 96
@@ -176,7 +176,7 @@ export class AccountModel extends Model<AccountModel> {
176 return undefined 176 return undefined
177 } 177 }
178 178
179 static load (id: number, transaction?: Sequelize.Transaction) { 179 static load (id: number, transaction?: Transaction) {
180 return AccountModel.findByPk(id, { transaction }) 180 return AccountModel.findByPk(id, { transaction })
181 } 181 }
182 182
@@ -207,15 +207,15 @@ export class AccountModel extends Model<AccountModel> {
207 static loadLocalByName (name: string) { 207 static loadLocalByName (name: string) {
208 const query = { 208 const query = {
209 where: { 209 where: {
210 [ Sequelize.Op.or ]: [ 210 [ Op.or ]: [
211 { 211 {
212 userId: { 212 userId: {
213 [ Sequelize.Op.ne ]: null 213 [ Op.ne ]: null
214 } 214 }
215 }, 215 },
216 { 216 {
217 applicationId: { 217 applicationId: {
218 [ Sequelize.Op.ne ]: null 218 [ Op.ne ]: null
219 } 219 }
220 } 220 }
221 ] 221 ]
@@ -259,7 +259,7 @@ export class AccountModel extends Model<AccountModel> {
259 return AccountModel.findOne(query) 259 return AccountModel.findOne(query)
260 } 260 }
261 261
262 static loadByUrl (url: string, transaction?: Sequelize.Transaction) { 262 static loadByUrl (url: string, transaction?: Transaction) {
263 const query = { 263 const query = {
264 include: [ 264 include: [
265 { 265 {
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts
index 33480f3b5..08388f268 100644
--- a/server/models/account/user-notification.ts
+++ b/server/models/account/user-notification.ts
@@ -1,17 +1,4 @@
1import { 1import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2 AllowNull,
3 BelongsTo,
4 Column,
5 CreatedAt,
6 Default,
7 ForeignKey,
8 IFindOptions,
9 Is,
10 Model,
11 Scopes,
12 Table,
13 UpdatedAt
14} from 'sequelize-typescript'
15import { UserNotification, UserNotificationType } from '../../../shared' 2import { UserNotification, UserNotificationType } from '../../../shared'
16import { getSort, throwIfNotValid } from '../utils' 3import { getSort, throwIfNotValid } from '../utils'
17import { isBooleanValid } from '../../helpers/custom-validators/misc' 4import { isBooleanValid } from '../../helpers/custom-validators/misc'
@@ -19,7 +6,7 @@ import { isUserNotificationTypeValid } from '../../helpers/custom-validators/use
19import { UserModel } from './user' 6import { UserModel } from './user'
20import { VideoModel } from '../video/video' 7import { VideoModel } from '../video/video'
21import { VideoCommentModel } from '../video/video-comment' 8import { VideoCommentModel } from '../video/video-comment'
22import { Op } from 'sequelize' 9import { FindOptions, Op } from 'sequelize'
23import { VideoChannelModel } from '../video/video-channel' 10import { VideoChannelModel } from '../video/video-channel'
24import { AccountModel } from './account' 11import { AccountModel } from './account'
25import { VideoAbuseModel } from '../video/video-abuse' 12import { VideoAbuseModel } from '../video/video-abuse'
@@ -160,7 +147,7 @@ function buildAccountInclude (required: boolean, withActor = false) {
160 }, 147 },
161 148
162 buildAccountInclude(false, true) 149 buildAccountInclude(false, true)
163 ] 150 ] as any // FIXME: sequelize typings
164 } 151 }
165}) 152})
166@Table({ 153@Table({
@@ -225,7 +212,7 @@ function buildAccountInclude (required: boolean, withActor = false) {
225 } 212 }
226 } 213 }
227 } 214 }
228 ] 215 ] as any // FIXME: sequelize typings
229}) 216})
230export class UserNotificationModel extends Model<UserNotificationModel> { 217export class UserNotificationModel extends Model<UserNotificationModel> {
231 218
@@ -344,7 +331,7 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
344 ActorFollow: ActorFollowModel 331 ActorFollow: ActorFollowModel
345 332
346 static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) { 333 static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
347 const query: IFindOptions<UserNotificationModel> = { 334 const query: FindOptions = {
348 offset: start, 335 offset: start,
349 limit: count, 336 limit: count,
350 order: getSort(sort), 337 order: getSort(sort),
diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts
index 49d2def81..a862fc45f 100644
--- a/server/models/account/user-video-history.ts
+++ b/server/models/account/user-video-history.ts
@@ -76,7 +76,7 @@ export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> {
76 } 76 }
77 77
78 if (beforeDate) { 78 if (beforeDate) {
79 query.where.updatedAt = { 79 query.where['updatedAt'] = {
80 [Op.lt]: beforeDate 80 [Op.lt]: beforeDate
81 } 81 }
82 } 82 }
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index b66458351..8bd0397dd 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -80,7 +80,7 @@ enum ScopeNames {
80 model: () => UserNotificationSettingModel, 80 model: () => UserNotificationSettingModel,
81 required: true 81 required: true
82 } 82 }
83 ] 83 ] as any // FIXME: sequelize typings
84 } 84 }
85}) 85})
86@Table({ 86@Table({
@@ -115,13 +115,13 @@ export class UserModel extends Model<UserModel> {
115 115
116 @AllowNull(true) 116 @AllowNull(true)
117 @Default(null) 117 @Default(null)
118 @Is('UserEmailVerified', value => throwIfNotValid(value, isUserEmailVerifiedValid, 'email verified boolean')) 118 @Is('UserEmailVerified', value => throwIfNotValid(value, isUserEmailVerifiedValid, 'email verified boolean', true))
119 @Column 119 @Column
120 emailVerified: boolean 120 emailVerified: boolean
121 121
122 @AllowNull(false) 122 @AllowNull(false)
123 @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy')) 123 @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy'))
124 @Column(DataType.ENUM(values(NSFW_POLICY_TYPES))) 124 @Column(DataType.ENUM(...values(NSFW_POLICY_TYPES)))
125 nsfwPolicy: NSFWPolicyType 125 nsfwPolicy: NSFWPolicyType
126 126
127 @AllowNull(false) 127 @AllowNull(false)
@@ -156,7 +156,7 @@ export class UserModel extends Model<UserModel> {
156 156
157 @AllowNull(true) 157 @AllowNull(true)
158 @Default(null) 158 @Default(null)
159 @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason')) 159 @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason', true))
160 @Column 160 @Column
161 blockedReason: string 161 blockedReason: string
162 162
@@ -556,10 +556,10 @@ export class UserModel extends Model<UserModel> {
556 notificationSettings: this.NotificationSetting ? this.NotificationSetting.toFormattedJSON() : undefined, 556 notificationSettings: this.NotificationSetting ? this.NotificationSetting.toFormattedJSON() : undefined,
557 videoChannels: [], 557 videoChannels: [],
558 videoQuotaUsed: videoQuotaUsed !== undefined 558 videoQuotaUsed: videoQuotaUsed !== undefined
559 ? parseInt(videoQuotaUsed, 10) 559 ? parseInt(videoQuotaUsed + '', 10)
560 : undefined, 560 : undefined,
561 videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined 561 videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined
562 ? parseInt(videoQuotaUsedDaily, 10) 562 ? parseInt(videoQuotaUsedDaily + '', 10)
563 : undefined 563 : undefined
564 } 564 }
565 565
@@ -619,14 +619,14 @@ export class UserModel extends Model<UserModel> {
619 private static getTotalRawQuery (query: string, userId: number) { 619 private static getTotalRawQuery (query: string, userId: number) {
620 const options = { 620 const options = {
621 bind: { userId }, 621 bind: { userId },
622 type: Sequelize.QueryTypes.SELECT 622 type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT
623 } 623 }
624 624
625 return UserModel.sequelize.query(query, options) 625 return UserModel.sequelize.query<{ total: number }>(query, options)
626 .then(([ { total } ]) => { 626 .then(([ { total } ]) => {
627 if (total === null) return 0 627 if (total === null) return 0
628 628
629 return parseInt(total, 10) 629 return parseInt(total + '', 10)
630 }) 630 })
631 } 631 }
632} 632}