]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/abuse/abuse.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / abuse / abuse.ts
index 290270fe284305a6e78332694f8a2be847f6cd57..3518f5c02983b227554391b313d5845f480dc633 100644 (file)
@@ -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, AttributesOnly } from '@shared/core-utils'
 import {
   AbuseFilter,
   AbuseObject,
@@ -188,7 +187,7 @@ export enum ScopeNames {
     }
   ]
 })
-export class AbuseModel extends Model<AbuseModel> {
+export class AbuseModel extends Model<Partial<AttributesOnly<AbuseModel>>> {
 
   @AllowNull(false)
   @Default(null)
@@ -265,7 +264,7 @@ export class AbuseModel extends Model<AbuseModel> {
   })
   VideoAbuse: VideoAbuseModel
 
-  static loadByIdWithReporter (id: number): Bluebird<MAbuseReporter> {
+  static loadByIdWithReporter (id: number): Promise<MAbuseReporter> {
     const query = {
       where: {
         id
@@ -281,7 +280,7 @@ export class AbuseModel extends Model<AbuseModel> {
     return AbuseModel.findOne(query)
   }
 
-  static loadFull (id: number): Bluebird<MAbuseFull> {
+  static loadFull (id: number): Promise<MAbuseFull> {
     const query = {
       where: {
         id
@@ -435,10 +434,10 @@ export class AbuseModel extends Model<AbuseModel> {
   }
 
   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,