From 1735c825726edaa0af5035cb6cbb0cc0db502c6d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Apr 2019 11:28:17 +0200 Subject: Update sequelize --- server/models/account/account-video-rate.ts | 17 ++++++++--------- server/models/account/account.ts | 16 ++++++++-------- server/models/account/user-notification.ts | 23 +++++------------------ server/models/account/user-video-history.ts | 2 +- server/models/account/user.ts | 18 +++++++++--------- 5 files changed, 31 insertions(+), 45 deletions(-) (limited to 'server/models/account') 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 @@ import { values } from 'lodash' -import { Transaction, Op } from 'sequelize' +import { FindOptions, Op, Transaction } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' -import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions' import { VideoRateType } from '../../../shared/models/videos' import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' import { VideoModel } from '../video/video' import { AccountModel } from './account' import { ActorModel } from '../activitypub/actor' -import { throwIfNotValid, getSort } from '../utils' +import { getSort, throwIfNotValid } from '../utils' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { AccountVideoRate } from '../../../shared' -import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel' +import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from '../video/video-channel' /* Account rates per video. @@ -40,7 +39,7 @@ import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../vide export class AccountVideoRateModel extends Model { @AllowNull(false) - @Column(DataType.ENUM(values(VIDEO_RATE_TYPES))) + @Column(DataType.ENUM(...values(VIDEO_RATE_TYPES))) type: VideoRateType @AllowNull(false) @@ -79,7 +78,7 @@ export class AccountVideoRateModel extends Model { Account: AccountModel static load (accountId: number, videoId: number, transaction?: Transaction) { - const options: IFindOptions = { + const options: FindOptions = { where: { accountId, videoId @@ -97,7 +96,7 @@ export class AccountVideoRateModel extends Model { type?: string, accountId: number }) { - const query: IFindOptions = { + const query: FindOptions = { offset: options.start, limit: options.count, order: getSort(options.sort), @@ -123,7 +122,7 @@ export class AccountVideoRateModel extends Model { } static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) { - const options: IFindOptions = { + const options: FindOptions = { where: { videoId, type: rateType @@ -155,7 +154,7 @@ export class AccountVideoRateModel extends Model { } static loadByUrl (url: string, transaction: Transaction) { - const options: IFindOptions = { + const options: FindOptions = { where: { url } 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 @@ -import * as Sequelize from 'sequelize' import { AllowNull, BeforeDestroy, @@ -28,6 +27,7 @@ import { UserModel } from './user' import { AvatarModel } from '../avatar/avatar' import { VideoPlaylistModel } from '../video/video-playlist' import { WEBSERVER } from '../../initializers/constants' +import { Op, Transaction, WhereOptions } from 'sequelize' export enum ScopeNames { SUMMARY = 'SUMMARY' @@ -42,7 +42,7 @@ export enum ScopeNames { ] }) @Scopes({ - [ ScopeNames.SUMMARY ]: (whereActor?: Sequelize.WhereOptions) => { + [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions) => { return { attributes: [ 'id', 'name' ], include: [ @@ -90,7 +90,7 @@ export class AccountModel extends Model { @AllowNull(true) @Default(null) - @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description')) + @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description', true)) @Column description: string @@ -176,7 +176,7 @@ export class AccountModel extends Model { return undefined } - static load (id: number, transaction?: Sequelize.Transaction) { + static load (id: number, transaction?: Transaction) { return AccountModel.findByPk(id, { transaction }) } @@ -207,15 +207,15 @@ export class AccountModel extends Model { static loadLocalByName (name: string) { const query = { where: { - [ Sequelize.Op.or ]: [ + [ Op.or ]: [ { userId: { - [ Sequelize.Op.ne ]: null + [ Op.ne ]: null } }, { applicationId: { - [ Sequelize.Op.ne ]: null + [ Op.ne ]: null } } ] @@ -259,7 +259,7 @@ export class AccountModel extends Model { return AccountModel.findOne(query) } - static loadByUrl (url: string, transaction?: Sequelize.Transaction) { + static loadByUrl (url: string, transaction?: Transaction) { const query = { include: [ { 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 @@ -import { - AllowNull, - BelongsTo, - Column, - CreatedAt, - Default, - ForeignKey, - IFindOptions, - Is, - Model, - Scopes, - Table, - UpdatedAt -} from 'sequelize-typescript' +import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { UserNotification, UserNotificationType } from '../../../shared' import { getSort, throwIfNotValid } from '../utils' import { isBooleanValid } from '../../helpers/custom-validators/misc' @@ -19,7 +6,7 @@ import { isUserNotificationTypeValid } from '../../helpers/custom-validators/use import { UserModel } from './user' import { VideoModel } from '../video/video' import { VideoCommentModel } from '../video/video-comment' -import { Op } from 'sequelize' +import { FindOptions, Op } from 'sequelize' import { VideoChannelModel } from '../video/video-channel' import { AccountModel } from './account' import { VideoAbuseModel } from '../video/video-abuse' @@ -160,7 +147,7 @@ function buildAccountInclude (required: boolean, withActor = false) { }, buildAccountInclude(false, true) - ] + ] as any // FIXME: sequelize typings } }) @Table({ @@ -225,7 +212,7 @@ function buildAccountInclude (required: boolean, withActor = false) { } } } - ] + ] as any // FIXME: sequelize typings }) export class UserNotificationModel extends Model { @@ -344,7 +331,7 @@ export class UserNotificationModel extends Model { ActorFollow: ActorFollowModel static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) { - const query: IFindOptions = { + const query: FindOptions = { offset: start, limit: count, 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 { } if (beforeDate) { - query.where.updatedAt = { + query.where['updatedAt'] = { [Op.lt]: beforeDate } } 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 { model: () => UserNotificationSettingModel, required: true } - ] + ] as any // FIXME: sequelize typings } }) @Table({ @@ -115,13 +115,13 @@ export class UserModel extends Model { @AllowNull(true) @Default(null) - @Is('UserEmailVerified', value => throwIfNotValid(value, isUserEmailVerifiedValid, 'email verified boolean')) + @Is('UserEmailVerified', value => throwIfNotValid(value, isUserEmailVerifiedValid, 'email verified boolean', true)) @Column emailVerified: boolean @AllowNull(false) @Is('UserNSFWPolicy', value => throwIfNotValid(value, isUserNSFWPolicyValid, 'NSFW policy')) - @Column(DataType.ENUM(values(NSFW_POLICY_TYPES))) + @Column(DataType.ENUM(...values(NSFW_POLICY_TYPES))) nsfwPolicy: NSFWPolicyType @AllowNull(false) @@ -156,7 +156,7 @@ export class UserModel extends Model { @AllowNull(true) @Default(null) - @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason')) + @Is('UserBlockedReason', value => throwIfNotValid(value, isUserBlockedReasonValid, 'blocked reason', true)) @Column blockedReason: string @@ -556,10 +556,10 @@ export class UserModel extends Model { notificationSettings: this.NotificationSetting ? this.NotificationSetting.toFormattedJSON() : undefined, videoChannels: [], videoQuotaUsed: videoQuotaUsed !== undefined - ? parseInt(videoQuotaUsed, 10) + ? parseInt(videoQuotaUsed + '', 10) : undefined, videoQuotaUsedDaily: videoQuotaUsedDaily !== undefined - ? parseInt(videoQuotaUsedDaily, 10) + ? parseInt(videoQuotaUsedDaily + '', 10) : undefined } @@ -619,14 +619,14 @@ export class UserModel extends Model { private static getTotalRawQuery (query: string, userId: number) { const options = { bind: { userId }, - type: Sequelize.QueryTypes.SELECT + type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } - return UserModel.sequelize.query(query, options) + return UserModel.sequelize.query<{ total: number }>(query, options) .then(([ { total } ]) => { if (total === null) return 0 - return parseInt(total, 10) + return parseInt(total + '', 10) }) } } -- cgit v1.2.3