aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/user.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-08 14:30:29 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-09 11:41:22 +0100
commitb49f22d8f9a52ab75fd38db2d377249eb58fa678 (patch)
treea2825877d7b3b53454804a79c9d2a14c5d37385c /server/models/account/user.ts
parent6c8c15f914cd375da1db5d0cd4d924a86c53d4c1 (diff)
downloadPeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.gz
PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.zst
PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.zip
Upgrade sequelize to v6
Diffstat (limited to 'server/models/account/user.ts')
-rw-r--r--server/models/account/user.ts35
1 files changed, 17 insertions, 18 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 10117099b..8e437c3be 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -1,4 +1,3 @@
1import * as Bluebird from 'bluebird'
2import { values } from 'lodash' 1import { values } from 'lodash'
3import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize' 2import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize'
4import { 3import {
@@ -16,11 +15,11 @@ import {
16 HasOne, 15 HasOne,
17 Is, 16 Is,
18 IsEmail, 17 IsEmail,
18 IsUUID,
19 Model, 19 Model,
20 Scopes, 20 Scopes,
21 Table, 21 Table,
22 UpdatedAt, 22 UpdatedAt
23 IsUUID
24} from 'sequelize-typescript' 23} from 'sequelize-typescript'
25import { 24import {
26 MMyUserFormattable, 25 MMyUserFormattable,
@@ -220,7 +219,7 @@ enum ScopeNames {
220 } 219 }
221 ] 220 ]
222}) 221})
223export class UserModel extends Model<UserModel> { 222export class UserModel extends Model {
224 223
225 @AllowNull(true) 224 @AllowNull(true)
226 @Is('UserPassword', value => throwIfNotValid(value, isUserPasswordValid, 'user password', true)) 225 @Is('UserPassword', value => throwIfNotValid(value, isUserPasswordValid, 'user password', true))
@@ -483,7 +482,7 @@ export class UserModel extends Model<UserModel> {
483 }) 482 })
484 } 483 }
485 484
486 static listWithRight (right: UserRight): Bluebird<MUserDefault[]> { 485 static listWithRight (right: UserRight): Promise<MUserDefault[]> {
487 const roles = Object.keys(USER_ROLE_LABELS) 486 const roles = Object.keys(USER_ROLE_LABELS)
488 .map(k => parseInt(k, 10) as UserRole) 487 .map(k => parseInt(k, 10) as UserRole)
489 .filter(role => hasUserRight(role, right)) 488 .filter(role => hasUserRight(role, right))
@@ -499,7 +498,7 @@ export class UserModel extends Model<UserModel> {
499 return UserModel.findAll(query) 498 return UserModel.findAll(query)
500 } 499 }
501 500
502 static listUserSubscribersOf (actorId: number): Bluebird<MUserWithNotificationSetting[]> { 501 static listUserSubscribersOf (actorId: number): Promise<MUserWithNotificationSetting[]> {
503 const query = { 502 const query = {
504 include: [ 503 include: [
505 { 504 {
@@ -538,7 +537,7 @@ export class UserModel extends Model<UserModel> {
538 return UserModel.unscoped().findAll(query) 537 return UserModel.unscoped().findAll(query)
539 } 538 }
540 539
541 static listByUsernames (usernames: string[]): Bluebird<MUserDefault[]> { 540 static listByUsernames (usernames: string[]): Promise<MUserDefault[]> {
542 const query = { 541 const query = {
543 where: { 542 where: {
544 username: usernames 543 username: usernames
@@ -548,11 +547,11 @@ export class UserModel extends Model<UserModel> {
548 return UserModel.findAll(query) 547 return UserModel.findAll(query)
549 } 548 }
550 549
551 static loadById (id: number): Bluebird<MUser> { 550 static loadById (id: number): Promise<MUser> {
552 return UserModel.unscoped().findByPk(id) 551 return UserModel.unscoped().findByPk(id)
553 } 552 }
554 553
555 static loadByIdWithChannels (id: number, withStats = false): Bluebird<MUserDefault> { 554 static loadByIdWithChannels (id: number, withStats = false): Promise<MUserDefault> {
556 const scopes = [ 555 const scopes = [
557 ScopeNames.WITH_VIDEOCHANNELS 556 ScopeNames.WITH_VIDEOCHANNELS
558 ] 557 ]
@@ -562,7 +561,7 @@ export class UserModel extends Model<UserModel> {
562 return UserModel.scope(scopes).findByPk(id) 561 return UserModel.scope(scopes).findByPk(id)
563 } 562 }
564 563
565 static loadByUsername (username: string): Bluebird<MUserDefault> { 564 static loadByUsername (username: string): Promise<MUserDefault> {
566 const query = { 565 const query = {
567 where: { 566 where: {
568 username: { [Op.iLike]: username } 567 username: { [Op.iLike]: username }
@@ -572,7 +571,7 @@ export class UserModel extends Model<UserModel> {
572 return UserModel.findOne(query) 571 return UserModel.findOne(query)
573 } 572 }
574 573
575 static loadForMeAPI (username: string): Bluebird<MUserNotifSettingChannelDefault> { 574 static loadForMeAPI (username: string): Promise<MUserNotifSettingChannelDefault> {
576 const query = { 575 const query = {
577 where: { 576 where: {
578 username: { [Op.iLike]: username } 577 username: { [Op.iLike]: username }
@@ -582,7 +581,7 @@ export class UserModel extends Model<UserModel> {
582 return UserModel.scope(ScopeNames.FOR_ME_API).findOne(query) 581 return UserModel.scope(ScopeNames.FOR_ME_API).findOne(query)
583 } 582 }
584 583
585 static loadByEmail (email: string): Bluebird<MUserDefault> { 584 static loadByEmail (email: string): Promise<MUserDefault> {
586 const query = { 585 const query = {
587 where: { 586 where: {
588 email 587 email
@@ -592,7 +591,7 @@ export class UserModel extends Model<UserModel> {
592 return UserModel.findOne(query) 591 return UserModel.findOne(query)
593 } 592 }
594 593
595 static loadByUsernameOrEmail (username: string, email?: string): Bluebird<MUserDefault> { 594 static loadByUsernameOrEmail (username: string, email?: string): Promise<MUserDefault> {
596 if (!email) email = username 595 if (!email) email = username
597 596
598 const query = { 597 const query = {
@@ -608,7 +607,7 @@ export class UserModel extends Model<UserModel> {
608 return UserModel.findOne(query) 607 return UserModel.findOne(query)
609 } 608 }
610 609
611 static loadByVideoId (videoId: number): Bluebird<MUserDefault> { 610 static loadByVideoId (videoId: number): Promise<MUserDefault> {
612 const query = { 611 const query = {
613 include: [ 612 include: [
614 { 613 {
@@ -639,7 +638,7 @@ export class UserModel extends Model<UserModel> {
639 return UserModel.findOne(query) 638 return UserModel.findOne(query)
640 } 639 }
641 640
642 static loadByVideoImportId (videoImportId: number): Bluebird<MUserDefault> { 641 static loadByVideoImportId (videoImportId: number): Promise<MUserDefault> {
643 const query = { 642 const query = {
644 include: [ 643 include: [
645 { 644 {
@@ -656,7 +655,7 @@ export class UserModel extends Model<UserModel> {
656 return UserModel.findOne(query) 655 return UserModel.findOne(query)
657 } 656 }
658 657
659 static loadByChannelActorId (videoChannelActorId: number): Bluebird<MUserDefault> { 658 static loadByChannelActorId (videoChannelActorId: number): Promise<MUserDefault> {
660 const query = { 659 const query = {
661 include: [ 660 include: [
662 { 661 {
@@ -680,7 +679,7 @@ export class UserModel extends Model<UserModel> {
680 return UserModel.findOne(query) 679 return UserModel.findOne(query)
681 } 680 }
682 681
683 static loadByAccountActorId (accountActorId: number): Bluebird<MUserDefault> { 682 static loadByAccountActorId (accountActorId: number): Promise<MUserDefault> {
684 const query = { 683 const query = {
685 include: [ 684 include: [
686 { 685 {
@@ -697,7 +696,7 @@ export class UserModel extends Model<UserModel> {
697 return UserModel.findOne(query) 696 return UserModel.findOne(query)
698 } 697 }
699 698
700 static loadByLiveId (liveId: number): Bluebird<MUser> { 699 static loadByLiveId (liveId: number): Promise<MUser> {
701 const query = { 700 const query = {
702 include: [ 701 include: [
703 { 702 {