aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/sql/comment/video-comment-table-attributes.ts71
-rw-r--r--server/models/video/video-comment.ts14
2 files changed, 31 insertions, 54 deletions
diff --git a/server/models/video/sql/comment/video-comment-table-attributes.ts b/server/models/video/sql/comment/video-comment-table-attributes.ts
index cae3c1683..10e635e41 100644
--- a/server/models/video/sql/comment/video-comment-table-attributes.ts
+++ b/server/models/video/sql/comment/video-comment-table-attributes.ts
@@ -1,33 +1,23 @@
1import { Memoize } from '@server/helpers/memoize'
2import { AccountModel } from '@server/models/account/account'
3import { ActorModel } from '@server/models/actor/actor'
4import { ActorImageModel } from '@server/models/actor/actor-image'
5import { ServerModel } from '@server/models/server/server'
6import { VideoCommentModel } from '../../video-comment'
7
1export class VideoCommentTableAttributes { 8export class VideoCommentTableAttributes {
2 9
10 @Memoize()
3 getVideoCommentAttributes () { 11 getVideoCommentAttributes () {
4 return [ 12 return VideoCommentModel.getSQLAttributes('VideoCommentModel').join(', ')
5 '"VideoCommentModel"."id"',
6 '"VideoCommentModel"."url"',
7 '"VideoCommentModel"."deletedAt"',
8 '"VideoCommentModel"."updatedAt"',
9 '"VideoCommentModel"."createdAt"',
10 '"VideoCommentModel"."text"',
11 '"VideoCommentModel"."originCommentId"',
12 '"VideoCommentModel"."inReplyToCommentId"',
13 '"VideoCommentModel"."videoId"',
14 '"VideoCommentModel"."accountId"'
15 ].join(', ')
16 } 13 }
17 14
15 @Memoize()
18 getAccountAttributes () { 16 getAccountAttributes () {
19 return [ 17 return AccountModel.getSQLAttributes('Account', 'Account.').join(', ')
20 `"Account"."id" AS "Account.id"`,
21 `"Account"."name" AS "Account.name"`,
22 `"Account"."description" AS "Account.description"`,
23 `"Account"."createdAt" AS "Account.createdAt"`,
24 `"Account"."updatedAt" AS "Account.updatedAt"`,
25 `"Account"."actorId" AS "Account.actorId"`,
26 `"Account"."userId" AS "Account.userId"`,
27 `"Account"."applicationId" AS "Account.applicationId"`
28 ].join(', ')
29 } 18 }
30 19
20 @Memoize()
31 getVideoAttributes () { 21 getVideoAttributes () {
32 return [ 22 return [
33 `"Video"."id" AS "Video.id"`, 23 `"Video"."id" AS "Video.id"`,
@@ -36,43 +26,18 @@ export class VideoCommentTableAttributes {
36 ].join(', ') 26 ].join(', ')
37 } 27 }
38 28
29 @Memoize()
39 getActorAttributes () { 30 getActorAttributes () {
40 return [ 31 return ActorModel.getSQLAPIAttributes('Account->Actor', `Account.Actor.`).join(', ')
41 `"Account->Actor"."id" AS "Account.Actor.id"`,
42 `"Account->Actor"."type" AS "Account.Actor.type"`,
43 `"Account->Actor"."preferredUsername" AS "Account.Actor.preferredUsername"`,
44 `"Account->Actor"."url" AS "Account.Actor.url"`,
45 `"Account->Actor"."followersCount" AS "Account.Actor.followersCount"`,
46 `"Account->Actor"."followingCount" AS "Account.Actor.followingCount"`,
47 `"Account->Actor"."remoteCreatedAt" AS "Account.Actor.remoteCreatedAt"`,
48 `"Account->Actor"."serverId" AS "Account.Actor.serverId"`,
49 `"Account->Actor"."createdAt" AS "Account.Actor.createdAt"`,
50 `"Account->Actor"."updatedAt" AS "Account.Actor.updatedAt"`
51 ].join(', ')
52 } 32 }
53 33
34 @Memoize()
54 getServerAttributes () { 35 getServerAttributes () {
55 return [ 36 return ServerModel.getSQLAttributes('Account->Actor->Server', `Account.Actor.Server.`).join(', ')
56 `"Account->Actor->Server"."id" AS "Account.Actor.Server.id"`,
57 `"Account->Actor->Server"."host" AS "Account.Actor.Server.host"`,
58 `"Account->Actor->Server"."redundancyAllowed" AS "Account.Actor.Server.redundancyAllowed"`,
59 `"Account->Actor->Server"."createdAt" AS "Account.Actor.Server.createdAt"`,
60 `"Account->Actor->Server"."updatedAt" AS "Account.Actor.Server.updatedAt"`
61 ].join(', ')
62 } 37 }
63 38
39 @Memoize()
64 getAvatarAttributes () { 40 getAvatarAttributes () {
65 return [ 41 return ActorImageModel.getSQLAttributes('Account->Actor->Avatars', 'Account.Actor.Avatars.id').join(', ')
66 `"Account->Actor->Avatars"."id" AS "Account.Actor.Avatars.id"`,
67 `"Account->Actor->Avatars"."filename" AS "Account.Actor.Avatars.filename"`,
68 `"Account->Actor->Avatars"."height" AS "Account.Actor.Avatars.height"`,
69 `"Account->Actor->Avatars"."width" AS "Account.Actor.Avatars.width"`,
70 `"Account->Actor->Avatars"."fileUrl" AS "Account.Actor.Avatars.fileUrl"`,
71 `"Account->Actor->Avatars"."onDisk" AS "Account.Actor.Avatars.onDisk"`,
72 `"Account->Actor->Avatars"."type" AS "Account.Actor.Avatars.type"`,
73 `"Account->Actor->Avatars"."actorId" AS "Account.Actor.Avatars.actorId"`,
74 `"Account->Actor->Avatars"."createdAt" AS "Account.Actor.Avatars.createdAt"`,
75 `"Account->Actor->Avatars"."updatedAt" AS "Account.Actor.Avatars.updatedAt"`
76 ].join(', ')
77 } 42 }
78} 43}
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index fb9d15e55..28a3d723d 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -40,7 +40,7 @@ import {
40import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse' 40import { VideoCommentAbuseModel } from '../abuse/video-comment-abuse'
41import { AccountModel } from '../account/account' 41import { AccountModel } from '../account/account'
42import { ActorModel } from '../actor/actor' 42import { ActorModel } from '../actor/actor'
43import { buildLocalAccountIdsIn, throwIfNotValid } from '../utils' 43import { buildLocalAccountIdsIn, buildSQLAttributes, throwIfNotValid } from '../utils'
44import { ListVideoCommentsOptions, VideoCommentListQueryBuilder } from './sql/comment/video-comment-list-query-builder' 44import { ListVideoCommentsOptions, VideoCommentListQueryBuilder } from './sql/comment/video-comment-list-query-builder'
45import { VideoModel } from './video' 45import { VideoModel } from './video'
46import { VideoChannelModel } from './video-channel' 46import { VideoChannelModel } from './video-channel'
@@ -192,6 +192,18 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
192 }) 192 })
193 CommentAbuses: VideoCommentAbuseModel[] 193 CommentAbuses: VideoCommentAbuseModel[]
194 194
195 // ---------------------------------------------------------------------------
196
197 static getSQLAttributes (tableName: string, aliasPrefix = '') {
198 return buildSQLAttributes({
199 model: this,
200 tableName,
201 aliasPrefix
202 })
203 }
204
205 // ---------------------------------------------------------------------------
206
195 static loadById (id: number, t?: Transaction): Promise<MComment> { 207 static loadById (id: number, t?: Transaction): Promise<MComment> {
196 const query: FindOptions = { 208 const query: FindOptions = {
197 where: { 209 where: {