X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fabuse%2Fabuse.ts;h=4344df006ebb810dbf42a74ce0aaeda2907df1e9;hb=21d68e68039a1eefbe6213fbde46e737e520ee7d;hp=290270fe284305a6e78332694f8a2be847f6cd57;hpb=7a4ea932461f228ae44a173ddcd48ffb088aa023;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 290270fe2..4344df006 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts @@ -1,4 +1,3 @@ -import * as Bluebird from 'bluebird' import { invert } from 'lodash' import { literal, Op, QueryTypes } from 'sequelize' import { @@ -17,7 +16,7 @@ import { UpdatedAt } from 'sequelize-typescript' import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' -import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' +import { abusePredefinedReasonsMap } from '@shared/core-utils' import { AbuseFilter, AbuseObject, @@ -31,6 +30,7 @@ import { UserAbuse, UserVideoAbuse } from '@shared/models' +import { AttributesOnly } from '@shared/typescript-utils' import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' import { MAbuseAdminFormattable, MAbuseAP, MAbuseFull, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' @@ -188,7 +188,7 @@ export enum ScopeNames { } ] }) -export class AbuseModel extends Model { +export class AbuseModel extends Model>> { @AllowNull(false) @Default(null) @@ -265,7 +265,7 @@ export class AbuseModel extends Model { }) VideoAbuse: VideoAbuseModel - static loadByIdWithReporter (id: number): Bluebird { + static loadByIdWithReporter (id: number): Promise { const query = { where: { id @@ -281,7 +281,7 @@ export class AbuseModel extends Model { return AbuseModel.findOne(query) } - static loadFull (id: number): Bluebird { + static loadFull (id: number): Promise { const query = { where: { id @@ -435,10 +435,10 @@ export class AbuseModel extends Model { } buildBaseVideoCommentAbuse (this: MAbuseUserFormattable) { - if (!this.VideoCommentAbuse) return null + // Associated video comment could have been destroyed if the video has been deleted + if (!this.VideoCommentAbuse || !this.VideoCommentAbuse.VideoComment) return null - const abuseModel = this.VideoCommentAbuse - const entity = abuseModel.VideoComment + const entity = this.VideoCommentAbuse.VideoComment return { id: entity.id,