Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: hide user data from comments module
  • Loading branch information
gondar00 committed Aug 23, 2022
1 parent 8efc7a6 commit 45e0d33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion server/src/entities/comment.entity.ts
Expand Up @@ -44,7 +44,7 @@ export class Comment extends BaseEntity {
@UpdateDateColumn({ default: () => 'now()', name: 'updated_at' })
updatedAt: Date;

@OneToOne(() => User, (user) => user.id, { eager: true })
@OneToOne(() => User, (user) => user.id)
@JoinColumn({ name: 'user_id' })
user: User;

Expand Down
44 changes: 26 additions & 18 deletions server/src/services/comment.service.ts
Expand Up @@ -6,7 +6,7 @@ import { CommentRepository } from '../repositories/comment.repository';
import { CreateCommentDto, UpdateCommentDto } from '../dto/comment.dto';
import { groupBy, head } from 'lodash';
import { EmailService } from './email.service';
import { Repository } from 'typeorm';
import { createQueryBuilder, Repository } from 'typeorm';
import { AppVersion } from 'src/entities/app_version.entity';
import { User } from 'src/entities/user.entity';
import { CommentUsers } from 'src/entities/comment_user.entity';
Expand All @@ -23,7 +23,7 @@ export class CommentService {
@InjectRepository(CommentUsers)
private commentUsersRepository: Repository<CommentUsers>,
private emailService: EmailService
) {}
) { }

public async createComment(createCommentDto: CreateCommentDto, user: User): Promise<Comment> {
try {
Expand Down Expand Up @@ -64,15 +64,17 @@ export class CommentService {
}

public async getComments(threadId: string, appVersionsId: string): Promise<Comment[]> {
return await this.commentRepository.find({
where: {
return await createQueryBuilder(Comment, 'comment')
.innerJoin('comment.user', 'user')
.addSelect(['user.id', 'user.firstName', 'user.lastName'])
.andWhere('comment.threadId = :threadId', {
threadId,
})
.andWhere('comment.appVersionsId = :appVersionsId', {
appVersionsId,
},
order: {
createdAt: 'ASC',
},
});
})
.orderBy('comment.createdAt', 'ASC')
.getMany();
}

public async getOrganizationComments(organizationId: string, appVersionsId: string): Promise<Comment[]> {
Expand All @@ -93,16 +95,22 @@ export class CommentService {
isResolved = false,
appVersionsId: string
): Promise<Comment[]> {
const comments = await this.commentRepository.find({
where: {
thread: { appId, isResolved },
const comments = await createQueryBuilder(Comment, 'comment')
.innerJoin('comment.user', 'user')
.addSelect(['user.id', 'user.firstName', 'user.lastName'])
.innerJoin('comment.thread', 'thread')
.addSelect(['thread.id'])
.andWhere('thread.appId = :appId', {
appId,
})
.andWhere('thread.isResolved = :isResolved', {
isResolved,
})
.andWhere('comment.appVersionsId = :appVersionsId', {
appVersionsId,
},
order: {
createdAt: 'DESC',
},
relations: ['thread'],
});
})
.orderBy('comment.createdAt', 'DESC')
.getMany();

const groupedComments = groupBy(comments, 'threadId');

Expand Down

0 comments on commit 45e0d33

Please sign in to comment.