diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-03 10:23:44 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-03 10:23:44 +0100 |
commit | 156c44c8f6522686635089ecff7a358b4145d545 (patch) | |
tree | 770d4b8b154ee0942fc7e37ffd697a3b7ec02c71 /server/models/user/sql | |
parent | bf521f51fc561b38d2e1432213a75427f671dda9 (diff) | |
download | PeerTube-156c44c8f6522686635089ecff7a358b4145d545.tar.gz PeerTube-156c44c8f6522686635089ecff7a358b4145d545.tar.zst PeerTube-156c44c8f6522686635089ecff7a358b4145d545.zip |
Refactor a little bit raw sql builders
Diffstat (limited to 'server/models/user/sql')
-rw-r--r-- | server/models/user/sql/user-notitication-list-query-builder.ts | 25 |
1 files changed, 10 insertions, 15 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 | } |