Skip to content

Commit 3f83172

Browse files
authored
fix(bookmarks): is_bookmarked
1 parent 8698656 commit 3f83172

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/tweets/dto/tweet-response.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class TweetResponseDTO {
169169
is_reposted?: boolean = false;
170170

171171
@Expose()
172-
@Transform(({ obj }) => !!obj.current_user_bookmark)
172+
@Transform(({ obj }) => !!obj.current_user_bookmark || obj.is_bookmarked)
173173
@ApiProperty({
174174
description: 'Whether the current user has bookmarked this tweet',
175175
example: false,

src/tweets/tweets.repository.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ export class TweetsRepository extends Repository<Tweet> {
621621
WHERE tweet_reposts.tweet_id = ${alias}.tweet_id
622622
AND tweet_reposts.user_id = :current_user_id
623623
),
624+
'is_bookmarked', EXISTS(
625+
SELECT 1 FROM tweet_bookmarks
626+
WHERE tweet_bookmarks.tweet_id = ${alias}.tweet_id
627+
AND tweet_bookmarks.user_id = :current_user_id
628+
),
624629
'is_following', EXISTS(
625630
SELECT 1 FROM user_follows
626631
WHERE user_follows.follower_id = :current_user_id
@@ -734,6 +739,11 @@ export class TweetsRepository extends Repository<Tweet> {
734739
WHERE tweet_reposts.tweet_id = ${alias}.tweet_id
735740
AND tweet_reposts.user_id = :current_user_id
736741
),
742+
'is_bookmarked', EXISTS(
743+
SELECT 1 FROM tweet_bookmarks
744+
WHERE tweet_bookmarks.tweet_id = ${alias}.tweet_id
745+
AND tweet_bookmarks.user_id = :current_user_id
746+
),
737747
'is_following', EXISTS(
738748
SELECT 1 FROM user_follows
739749
WHERE user_follows.follower_id = :current_user_id
@@ -882,6 +892,11 @@ export class TweetsRepository extends Repository<Tweet> {
882892
WHERE tweet_reposts.tweet_id = ${alias}.tweet_id
883893
AND tweet_reposts.user_id = :current_user_id
884894
),
895+
'is_bookmarked', EXISTS(
896+
SELECT 1 FROM tweet_bookmarks
897+
WHERE tweet_bookmarks.tweet_id = ${alias}.tweet_id
898+
AND tweet_bookmarks.user_id = :current_user_id
899+
),
885900
'is_following', EXISTS(
886901
SELECT 1 FROM user_follows
887902
WHERE user_follows.follower_id = :current_user_id
@@ -1001,6 +1016,14 @@ export class TweetsRepository extends Repository<Tweet> {
10011016
)`,
10021017
'is_reposted'
10031018
)
1019+
.addSelect(
1020+
`EXISTS(
1021+
SELECT 1 FROM tweet_bookmarks
1022+
WHERE tweet_bookmarks.tweet_id = ${tweet_id_column}
1023+
AND tweet_bookmarks.user_id = :current_user_id
1024+
)`,
1025+
'is_bookmarked'
1026+
)
10041027
.addSelect(
10051028
`EXISTS(
10061029
SELECT 1 FROM user_follows

0 commit comments

Comments
 (0)