Skip to content

Commit 15c3bf8

Browse files
Alyaa242AmiraKhalid04MarioRaafat
authored
feat(profile): v4
* feat(profile): profile posts tabs endpoints * fix(profile): fix update user response * fix(profile): return user birthdate in profile response * fix(profile): clean unused files after update profile * refactor(profile): convert sql posts query to typeorm * feat(profile): add user data to user posts view * fix(profile): remove reply from user posts + fix repost type * feat(profile): add quote parent data in user posts * feat(profile): apply cursor pagination to profile endpoints * fix(profile): fix get media + liked posts * refactor(profile): change response pagination schema * docs(profile): edit swagger documentation for pagination * fix(profile): fix cursor pagination and created_at timezone * fix(profile): replace location with country in update user * fix(profile): delete profile, cover images after delete account * feat(user): get username recommendations * fix(auth): fix refresh token * feat(auth): confirm password * feat(Profile): get user replies * fix(profile): check if user exists in user posts tabs * fix(profile): fix user replies interactions --------- Co-authored-by: Amira Khalid <149877108+AmiraKhalid04@users.noreply.github.com> Co-authored-by: Mario Raafat <136023677+MarioRaafat@users.noreply.github.com>
1 parent dfe716b commit 15c3bf8

File tree

3 files changed

+193
-135
lines changed

3 files changed

+193
-135
lines changed

src/tweets/tweets.repository.ts

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ export class TweetsRepository {
487487
'tweet_id'
488488
);
489489

490-
const tweets = await query.getRawMany();
490+
let tweets = await query.getRawMany();
491+
tweets = this.attachUserFollowFlags(tweets);
491492

492493
const tweet_dtos = tweets.map((reply) =>
493494
plainToInstance(TweetResponseDTO, reply, {
@@ -527,50 +528,82 @@ export class TweetsRepository {
527528
};
528529
}> {
529530
try {
530-
// Build query for replies by user
531-
let query = this.tweet_repository
531+
let query = this.user_posts_view_repository
532532
.createQueryBuilder('tweet')
533-
.innerJoin('tweet_replies', 'reply', 'reply.reply_tweet_id = tweet.tweet_id')
534-
.leftJoinAndSelect('tweet.user', 'user')
535-
.where('tweet.user_id = :user_id', { user_id })
536-
.andWhere('tweet.type = :type', { type: TweetType.REPLY })
533+
.select([
534+
'tweet.tweet_id AS tweet_id',
535+
'tweet.profile_user_id AS profile_user_id',
536+
'tweet.tweet_author_id AS tweet_author_id',
537+
'tweet.repost_id AS repost_id',
538+
'tweet.post_type AS post_type',
539+
'tweet.type AS type',
540+
'tweet.content AS content',
541+
'tweet.type AS type',
542+
'tweet.post_date AS post_date',
543+
'tweet.images AS images',
544+
'tweet.videos AS videos',
545+
'tweet.num_likes AS num_likes',
546+
'tweet.num_reposts AS num_reposts',
547+
'tweet.num_views AS num_views',
548+
'tweet.num_quotes AS num_quotes',
549+
'tweet.num_replies AS num_replies',
550+
'tweet.created_at AS created_at',
551+
'tweet.updated_at AS updated_at',
552+
`json_build_object(
553+
'id', tweet.tweet_author_id,
554+
'username', tweet.username,
555+
'name', tweet.name,
556+
'avatar_url', tweet.avatar_url,
557+
'cover_url', tweet.cover_url,
558+
'verified', tweet.verified,
559+
'bio', tweet.bio,
560+
'followers', tweet.followers,
561+
'following', tweet.following
562+
) AS user`,
563+
])
564+
.where('tweet.profile_user_id = :user_id', { user_id })
565+
.andWhere('tweet.type = :type', { type: 'reply' })
537566
.orderBy('tweet.created_at', 'DESC')
538567
.addOrderBy('tweet.tweet_id', 'DESC')
539-
.take(limit);
568+
.limit(limit);
569+
570+
query = this.attachUserInteractionBooleanFlags(
571+
query,
572+
current_user_id,
573+
'tweet.tweet_author_id',
574+
'tweet.tweet_id'
575+
);
540576

541-
// Add interaction flags if current_user_id is provided
542-
query = this.attachUserTweetInteractionFlags(query, current_user_id, 'tweet');
577+
query = this.attachRepliedTweetQuery(query, current_user_id);
543578

544-
// Apply cursor pagination
545-
this.paginate_service.applyCursorPagination(
579+
query = this.paginate_service.applyCursorPagination(
546580
query,
547581
cursor,
548582
'tweet',
549583
'created_at',
550584
'tweet_id'
551585
);
552586

553-
const replies = await query.getMany();
587+
let tweets = await query.getRawMany();
588+
tweets = this.attachUserFollowFlags(tweets);
554589

555-
// Transform to DTOs
556-
const reply_dtos = replies.map((reply) =>
590+
const tweet_dtos = tweets.map((reply) =>
557591
plainToInstance(TweetResponseDTO, reply, {
558592
excludeExtraneousValues: true,
559593
})
560594
);
561595

562-
// Generate next cursor
563596
const next_cursor = this.paginate_service.generateNextCursor(
564-
replies,
597+
tweets,
565598
'created_at',
566599
'tweet_id'
567600
);
568601

569602
return {
570-
data: reply_dtos,
603+
data: tweet_dtos,
571604
pagination: {
572605
next_cursor,
573-
has_more: replies.length === limit,
606+
has_more: tweets.length === limit,
574607
},
575608
};
576609
} catch (error) {
@@ -648,7 +681,8 @@ export class TweetsRepository {
648681
'tweet_id'
649682
);
650683

651-
const tweets = await query.getRawMany();
684+
let tweets = await query.getRawMany();
685+
tweets = this.attachUserFollowFlags(tweets);
652686

653687
const tweet_dtos = tweets.map((reply) =>
654688
plainToInstance(TweetResponseDTO, reply, {
@@ -748,7 +782,8 @@ export class TweetsRepository {
748782
'tweet_id'
749783
);
750784

751-
const tweets = await query.getRawMany();
785+
let tweets = await query.getRawMany();
786+
tweets = this.attachUserFollowFlags(tweets);
752787

753788
const tweet_dtos = tweets.map((reply) =>
754789
plainToInstance(TweetResponseDTO, reply, {

src/user/user.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ export class UserService {
465465
has_more: boolean;
466466
};
467467
}> {
468+
const exists = await this.user_repository.exists({ where: { id: target_user_id } });
469+
470+
if (!exists) {
471+
throw new NotFoundException(ERROR_MESSAGES.USER_NOT_FOUND);
472+
}
473+
468474
const { cursor, limit } = query_dto;
469475
return await this.tweets_repository.getPostsByUserId(
470476
target_user_id,
@@ -485,6 +491,12 @@ export class UserService {
485491
has_more: boolean;
486492
};
487493
}> {
494+
const exists = await this.user_repository.exists({ where: { id: target_user_id } });
495+
496+
if (!exists) {
497+
throw new NotFoundException(ERROR_MESSAGES.USER_NOT_FOUND);
498+
}
499+
488500
const { cursor, limit } = query_dto;
489501
return await this.tweets_repository.getRepliesByUserId(
490502
target_user_id,
@@ -505,6 +517,12 @@ export class UserService {
505517
has_more: boolean;
506518
};
507519
}> {
520+
const exists = await this.user_repository.exists({ where: { id: target_user_id } });
521+
522+
if (!exists) {
523+
throw new NotFoundException(ERROR_MESSAGES.USER_NOT_FOUND);
524+
}
525+
508526
const { cursor, limit } = query_dto;
509527
return await this.tweets_repository.getMediaByUserId(
510528
target_user_id,

0 commit comments

Comments
 (0)