diff options
Diffstat (limited to 'server/models/user')
-rw-r--r-- | server/models/user/sql/user-notitication-list-query-builder.ts | 25 | ||||
-rw-r--r-- | server/models/user/user-notification.ts | 5 |
2 files changed, 12 insertions, 18 deletions
diff --git a/server/models/user/sql/user-notitication-list-query-builder.ts b/server/models/user/sql/user-notitication-list-query-builder.ts index 9eae4fc22..6a6a71e3a 100644 --- a/server/models/user/sql/user-notitication-list-query-builder.ts +++ b/server/models/user/sql/user-notitication-list-query-builder.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { QueryTypes, Sequelize } from 'sequelize' | 1 | import { Sequelize } from 'sequelize' |
2 | import { ModelBuilder } from '@server/models/shared' | 2 | import { AbstractRunQuery, ModelBuilder } from '@server/models/shared' |
3 | import { getSort } from '@server/models/utils' | 3 | import { getSort } from '@server/models/utils' |
4 | import { UserNotificationModelForApi } from '@server/types/models' | 4 | import { UserNotificationModelForApi } from '@server/types/models' |
5 | import { ActorImageType } from '@shared/models' | 5 | import { ActorImageType } from '@shared/models' |
@@ -10,28 +10,23 @@ export interface ListNotificationsOptions { | |||
10 | sort: string | 10 | sort: string |
11 | offset: number | 11 | offset: number |
12 | limit: number | 12 | limit: number |
13 | sequelize: Sequelize | ||
14 | } | 13 | } |
15 | 14 | ||
16 | export class UserNotificationListQueryBuilder { | 15 | export class UserNotificationListQueryBuilder extends AbstractRunQuery { |
17 | private innerQuery: string | 16 | private innerQuery: string |
18 | private replacements: any = {} | ||
19 | private query: string | ||
20 | |||
21 | constructor (private readonly options: ListNotificationsOptions) { | ||
22 | 17 | ||
18 | constructor ( | ||
19 | protected readonly sequelize: Sequelize, | ||
20 | private readonly options: ListNotificationsOptions | ||
21 | ) { | ||
22 | super(sequelize) | ||
23 | } | 23 | } |
24 | 24 | ||
25 | async listNotifications () { | 25 | async listNotifications () { |
26 | this.buildQuery() | 26 | this.buildQuery() |
27 | 27 | ||
28 | const results = await this.options.sequelize.query(this.query, { | 28 | const results = await this.runQuery({ nest: true }) |
29 | replacements: this.replacements, | 29 | const modelBuilder = new ModelBuilder<UserNotificationModelForApi>(this.sequelize) |
30 | type: QueryTypes.SELECT, | ||
31 | nest: true | ||
32 | }) | ||
33 | |||
34 | const modelBuilder = new ModelBuilder<UserNotificationModelForApi>(this.options.sequelize) | ||
35 | 30 | ||
36 | return modelBuilder.createModels(results, 'UserNotification') | 31 | return modelBuilder.createModels(results, 'UserNotification') |
37 | } | 32 | } |
diff --git a/server/models/user/user-notification.ts b/server/models/user/user-notification.ts index eca127e7e..6209cb4bf 100644 --- a/server/models/user/user-notification.ts +++ b/server/models/user/user-notification.ts | |||
@@ -249,8 +249,7 @@ export class UserNotificationModel extends Model<Partial<AttributesOnly<UserNoti | |||
249 | offset: start, | 249 | offset: start, |
250 | limit: count, | 250 | limit: count, |
251 | sort, | 251 | sort, |
252 | where, | 252 | where |
253 | sequelize: this.sequelize | ||
254 | } | 253 | } |
255 | 254 | ||
256 | if (unread !== undefined) query.where['read'] = !unread | 255 | if (unread !== undefined) query.where['read'] = !unread |
@@ -261,7 +260,7 @@ export class UserNotificationModel extends Model<Partial<AttributesOnly<UserNoti | |||
261 | 260 | ||
262 | count === 0 | 261 | count === 0 |
263 | ? [] as UserNotificationModelForApi[] | 262 | ? [] as UserNotificationModelForApi[] |
264 | : new UserNotificationListQueryBuilder(query).listNotifications() | 263 | : new UserNotificationListQueryBuilder(this.sequelize, query).listNotifications() |
265 | ]).then(([ total, data ]) => ({ total, data })) | 264 | ]).then(([ total, data ]) => ({ total, data })) |
266 | } | 265 | } |
267 | 266 | ||