From 16c016e8b1d5ca46343d3363f9a49e24c5d7c944 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 12 May 2021 14:09:04 +0200 Subject: Stricter models typing --- server/models/user/user-notification-setting.ts | 3 ++- server/models/user/user-notification.ts | 3 ++- server/models/user/user-video-history.ts | 7 ++++--- server/models/user/user.ts | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'server/models/user') diff --git a/server/models/user/user-notification-setting.ts b/server/models/user/user-notification-setting.ts index 138051528..bee7d7851 100644 --- a/server/models/user/user-notification-setting.ts +++ b/server/models/user/user-notification-setting.ts @@ -14,6 +14,7 @@ import { } from 'sequelize-typescript' import { TokensCache } from '@server/lib/auth/tokens-cache' import { MNotificationSettingFormattable } from '@server/types/models' +import { AttributesOnly } from '@shared/core-utils' import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' import { throwIfNotValid } from '../utils' @@ -28,7 +29,7 @@ import { UserModel } from './user' } ] }) -export class UserNotificationSettingModel extends Model { +export class UserNotificationSettingModel extends Model>> { @AllowNull(false) @Default(null) diff --git a/server/models/user/user-notification.ts b/server/models/user/user-notification.ts index f7f9ac867..a7f84e9ca 100644 --- a/server/models/user/user-notification.ts +++ b/server/models/user/user-notification.ts @@ -1,6 +1,7 @@ import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' +import { AttributesOnly } from '@shared/core-utils' import { UserNotification, UserNotificationType } from '../../../shared' import { isBooleanValid } from '../../helpers/custom-validators/misc' import { isUserNotificationTypeValid } from '../../helpers/custom-validators/user-notifications' @@ -286,7 +287,7 @@ function buildAccountInclude (required: boolean, withActor = false) { } ] as (ModelIndexesOptions & { where?: WhereOptions })[] }) -export class UserNotificationModel extends Model { +export class UserNotificationModel extends Model>> { @AllowNull(false) @Default(null) diff --git a/server/models/user/user-video-history.ts b/server/models/user/user-video-history.ts index 6be1d65ea..e3dc4a062 100644 --- a/server/models/user/user-video-history.ts +++ b/server/models/user/user-video-history.ts @@ -1,8 +1,9 @@ +import { DestroyOptions, Op, Transaction } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { MUserAccountId, MUserId } from '@server/types/models' +import { AttributesOnly } from '@shared/core-utils' import { VideoModel } from '../video/video' import { UserModel } from './user' -import { DestroyOptions, Op, Transaction } from 'sequelize' -import { MUserAccountId, MUserId } from '@server/types/models' @Table({ tableName: 'userVideoHistory', @@ -19,7 +20,7 @@ import { MUserAccountId, MUserId } from '@server/types/models' } ] }) -export class UserVideoHistoryModel extends Model { +export class UserVideoHistoryModel extends Model>> { @CreatedAt createdAt: Date diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 8d2564e54..20696b1f4 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -31,6 +31,7 @@ import { MUserWithNotificationSetting, MVideoWithRights } from '@server/types/models' +import { AttributesOnly } from '@shared/core-utils' import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' import { User, UserRole } from '../../../shared/models/users' @@ -233,7 +234,7 @@ enum ScopeNames { } ] }) -export class UserModel extends Model { +export class UserModel extends Model>> { @AllowNull(true) @Is('UserPassword', value => throwIfNotValid(value, isUserPasswordValid, 'user password', true)) -- cgit v1.2.3