From 9b39106d5757caf221a88e42e05167a6fac479c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 21 Feb 2019 14:28:06 +0100 Subject: [PATCH] findById -> findByPk --- package.json | 4 ++-- .../migrations/0080-video-channels.ts | 2 +- server/models/account/account.ts | 3 +-- server/models/account/user.ts | 2 +- server/models/activitypub/actor.ts | 2 +- server/models/video/video-change-ownership.ts | 2 +- server/models/video/video-channel.ts | 6 +++--- server/models/video/video-file.ts | 2 +- server/models/video/video-import.ts | 2 +- server/models/video/video-streaming-playlist.ts | 2 +- server/models/video/video.ts | 2 +- .../tests/api/check-params/user-subscriptions.ts | 2 +- server/tests/api/server/email.ts | 3 ++- server/tests/api/server/follows.ts | 2 +- yarn.lock | 16 ++++++++-------- 15 files changed, 26 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index a4a545b54..fffbc8e32 100644 --- a/package.json +++ b/package.json @@ -142,8 +142,8 @@ "reflect-metadata": "^0.1.12", "request": "^2.81.0", "scripty": "^1.5.0", - "sequelize": "4.41.2", - "sequelize-typescript": "0.6.6", + "sequelize": "4.42.0", + "sequelize-typescript": "0.6.7", "sharp": "^0.21.0", "sitemap": "^2.1.0", "socket.io": "^2.2.0", diff --git a/server/initializers/migrations/0080-video-channels.ts b/server/initializers/migrations/0080-video-channels.ts index f19721517..0e17a4ccd 100644 --- a/server/initializers/migrations/0080-video-channels.ts +++ b/server/initializers/migrations/0080-video-channels.ts @@ -74,7 +74,7 @@ async function up (utils: { for (const rawVideo of rawVideos) { const videoChannel = await utils.db.VideoChannel.findOne({ where: { authorId: rawVideo.authorId } }) - const video = await utils.db.Video.findById(rawVideo.id) + const video = await utils.db.Video.findByPk(rawVideo.id) video.channelId = videoChannel.id await video.save() } diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 747b51afb..ee22d8528 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -24,7 +24,6 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { VideoCommentModel } from '../video/video-comment' import { UserModel } from './user' -import * as Bluebird from '../../helpers/custom-validators/accounts' import { CONFIG } from '../../initializers' @DefaultScope({ @@ -136,7 +135,7 @@ export class AccountModel extends Model { } static load (id: number, transaction?: Sequelize.Transaction) { - return AccountModel.findById(id, { transaction }) + return AccountModel.findByPk(id, { transaction }) } static loadByUUID (uuid: string) { diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 017a96657..8aff9f497 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -341,7 +341,7 @@ export class UserModel extends Model { } static loadById (id: number) { - return UserModel.findById(id) + return UserModel.findByPk(id) } static loadByUsername (username: string) { diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index dda57a8ba..49f82023b 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -265,7 +265,7 @@ export class ActorModel extends Model { VideoChannel: VideoChannelModel static load (id: number) { - return ActorModel.unscoped().findById(id) + return ActorModel.unscoped().findByPk(id) } static loadAccountActorByVideoId (videoId: number, transaction: Sequelize.Transaction) { diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index 48c07728f..85e688c4f 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts @@ -110,7 +110,7 @@ export class VideoChangeOwnershipModel extends Model } static load (id: number) { - return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findById(id) + return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findByPk(id) } toFormattedJSON (): VideoChangeOwnership { diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 91dd0440c..2426b3de6 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -320,7 +320,7 @@ export class VideoChannelModel extends Model { static loadByIdAndPopulateAccount (id: number) { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) - .findById(id) + .findByPk(id) } static loadByIdAndAccount (id: number, accountId: number) { @@ -339,7 +339,7 @@ export class VideoChannelModel extends Model { static loadAndPopulateAccount (id: number) { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) - .findById(id) + .findByPk(id) } static loadByUUIDAndPopulateAccount (uuid: string) { @@ -439,7 +439,7 @@ export class VideoChannelModel extends Model { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ]) - .findById(id, options) + .findByPk(id, options) } toFormattedJSON (): VideoChannel { diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 7d1e371b9..b861b0704 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -117,7 +117,7 @@ export class VideoFileModel extends Model { ] } - return VideoFileModel.findById(id, options) + return VideoFileModel.findByPk(id, options) } static async getStats () { diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts index c723e57c0..9bc0f17f5 100644 --- a/server/models/video/video-import.ts +++ b/server/models/video/video-import.ts @@ -115,7 +115,7 @@ export class VideoImportModel extends Model { } static loadAndPopulateVideo (id: number) { - return VideoImportModel.findById(id) + return VideoImportModel.findByPk(id) } static listUserVideoImportsForApi (userId: number, start: number, count: number, sort: string) { diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index bf6f7b0c4..e489f9b0e 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -110,7 +110,7 @@ export class VideoStreamingPlaylistModel extends Model { static loadWithFiles (id: number, t?: Sequelize.Transaction, logging?: boolean) { return VideoModel.scope([ ScopeNames.WITH_FILES, ScopeNames.WITH_STREAMING_PLAYLISTS ]) - .findById(id, { transaction: t, logging }) + .findByPk(id, { transaction: t, logging }) } static loadByUUIDWithFile (uuid: string) { diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 8a9ced7c1..04a3eb97c 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -212,7 +212,7 @@ describe('Test user subscriptions API validators', function () { }) }) - describe('When checking if subscriptions exist', async function () { + describe('When checking if subscriptions exist', function () { const existPath = path + '/exist' it('Should fail with a non authenticated user', async function () { diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index f8f16f54f..164905651 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -142,7 +142,8 @@ describe('Test emails', function () { }) }) - describe('When blocking/unblocking user', async function () { + describe('When blocking/unblocking user', function () { + it('Should send the notification email when blocking a user', async function () { this.timeout(10000) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index ad4c87c73..80f54b7ad 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -241,7 +241,7 @@ describe('Test follows', function () { expect(res.body.data[0].name).to.equal('server3') }) - describe('Should propagate data on a new following', async function () { + describe('Should propagate data on a new following', function () { let video4: Video before(async function () { diff --git a/yarn.lock b/yarn.lock index 4f9cf9503..4e6a5285b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7488,10 +7488,10 @@ send@0.16.2: range-parser "~1.2.0" statuses "~1.4.0" -sequelize-typescript@0.6.6: - version "0.6.6" - resolved "https://registry.yarnpkg.com/sequelize-typescript/-/sequelize-typescript-0.6.6.tgz#926037b542dae9f4eff20609d095cc5e3a3640f3" - integrity sha512-WGJTaNuHyYwUM8itxZvMVLeNEb7xSjisbVN1Q5rxLaIf2w67Xaf1GX6Jb+9840bjcNPvMsKgC2aR88zmw7UlcQ== +sequelize-typescript@0.6.7: + version "0.6.7" + resolved "https://registry.yarnpkg.com/sequelize-typescript/-/sequelize-typescript-0.6.7.tgz#372be979cbae060c554fdbaf2c2d8c93a0283303" + integrity sha512-ae21Gq9VOVXlIjnh2vLdL42Kev6r4LC82xOQ2fXo0lHzQvjFeH8/GaWUlpvYv57AOgc+ZnElbYFbSLKdT9ue0w== dependencies: "@types/bluebird" "3.5.18" "@types/node" "6.0.41" @@ -7499,10 +7499,10 @@ sequelize-typescript@0.6.6: es6-shim "0.35.3" glob "7.1.2" -sequelize@4.41.2: - version "4.41.2" - resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-4.41.2.tgz#bb9ba30d72e9eeb883c9861cd0e2cac672010883" - integrity sha512-8vPf2R0o9iEmtzkqNzwFdblO+0Mu+RNxOdLeYGGqWGlp3cushLpQucAeSGPQgf2hQVZP5yOCM1ouZKTQ5FTlvA== +sequelize@4.42.0: + version "4.42.0" + resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-4.42.0.tgz#439467ba7bfe7d5afcc56d62b3e091860fbf18f3" + integrity sha512-qxAYnX4rcv7PbNtEidb56REpxNJCdbN0qyk1jb3+e6sE7OrmS0nYMU+MFVbNTJtZfSpOEEL1TX0TkMw+wzZBxg== dependencies: bluebird "^3.5.0" cls-bluebird "^2.1.0" -- 2.41.0