aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/abuse
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/abuse')
-rw-r--r--server/models/abuse/abuse-message.ts32
1 files changed, 20 insertions, 12 deletions
diff --git a/server/models/abuse/abuse-message.ts b/server/models/abuse/abuse-message.ts
index 6a441a210..d9eb25f0f 100644
--- a/server/models/abuse/abuse-message.ts
+++ b/server/models/abuse/abuse-message.ts
@@ -1,11 +1,12 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' 2import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses'
3import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models' 3import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models'
4import { AttributesOnly } from '@shared/typescript-utils'
5import { AbuseMessage } from '@shared/models' 4import { AbuseMessage } from '@shared/models'
5import { AttributesOnly } from '@shared/typescript-utils'
6import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' 6import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account'
7import { getSort, throwIfNotValid } from '../utils' 7import { getSort, throwIfNotValid } from '../utils'
8import { AbuseModel } from './abuse' 8import { AbuseModel } from './abuse'
9import { FindOptions } from 'sequelize/dist'
9 10
10@Table({ 11@Table({
11 tableName: 'abuseMessage', 12 tableName: 'abuseMessage',
@@ -62,21 +63,28 @@ export class AbuseMessageModel extends Model<Partial<AttributesOnly<AbuseMessage
62 Abuse: AbuseModel 63 Abuse: AbuseModel
63 64
64 static listForApi (abuseId: number) { 65 static listForApi (abuseId: number) {
65 const options = { 66 const getQuery = (forCount: boolean) => {
66 where: { abuseId }, 67 const query: FindOptions = {
68 where: { abuseId },
69 order: getSort('createdAt')
70 }
67 71
68 order: getSort('createdAt'), 72 if (forCount !== true) {
73 query.include = [
74 {
75 model: AccountModel.scope(AccountScopeNames.SUMMARY),
76 required: false
77 }
78 ]
79 }
69 80
70 include: [ 81 return query
71 {
72 model: AccountModel.scope(AccountScopeNames.SUMMARY),
73 required: false
74 }
75 ]
76 } 82 }
77 83
78 return AbuseMessageModel.findAndCountAll(options) 84 return Promise.all([
79 .then(({ rows, count }) => ({ data: rows, total: count })) 85 AbuseMessageModel.count(getQuery(true)),
86 AbuseMessageModel.findAll(getQuery(false))
87 ]).then(([ total, data ]) => ({ total, data }))
80 } 88 }
81 89
82 static loadByIdAndAbuseId (messageId: number, abuseId: number): Promise<MAbuseMessage> { 90 static loadByIdAndAbuseId (messageId: number, abuseId: number): Promise<MAbuseMessage> {