From 37bf6de75f161e03c2a81888810488b913863a46 Mon Sep 17 00:00:00 2001 From: gandharv Date: Mon, 12 Sep 2022 13:06:22 +0530 Subject: [PATCH] fix: hide user data from thread module --- server/src/entities/thread.entity.ts | 2 +- server/src/services/thread.service.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/server/src/entities/thread.entity.ts b/server/src/entities/thread.entity.ts index 89871a6914..1918b55a6f 100644 --- a/server/src/entities/thread.entity.ts +++ b/server/src/entities/thread.entity.ts @@ -29,7 +29,7 @@ export class Thread extends BaseEntity { @Column({ default: false, name: 'is_resolved' }) isResolved: boolean; - @ManyToOne(() => User, (user) => user.id, { eager: true }) + @ManyToOne(() => User, (user) => user.id) @JoinColumn({ name: 'user_id' }) user: User; diff --git a/server/src/services/thread.service.ts b/server/src/services/thread.service.ts index 20ad2a0d40..0bf98528e3 100644 --- a/server/src/services/thread.service.ts +++ b/server/src/services/thread.service.ts @@ -4,6 +4,7 @@ import { Thread } from '../entities/thread.entity'; import { Comment } from '../entities/comment.entity'; import { CreateThreadDto, UpdateThreadDto } from '../dto/thread.dto'; import { ThreadRepository } from '../repositories/thread.repository'; +import { createQueryBuilder } from 'typeorm'; @Injectable() export class ThreadService { @@ -17,13 +18,19 @@ export class ThreadService { } public async getThreads(appId: string, organizationId: string, appVersionsId: string): Promise { - return await this.threadRepository.find({ - where: { + return await createQueryBuilder(Thread, 'thread') + .innerJoin('thread.user', 'user') + .addSelect(['user.id', 'user.firstName', 'user.lastName']) + .andWhere('thread.appId = :appId', { appId, + }) + .andWhere('thread.organizationId = :organizationId', { organizationId, + }) + .andWhere('thread.appVersionsId = :appVersionsId', { appVersionsId, - }, - }); + }) + .getMany(); } public async getOrganizationThreads(orgId: string): Promise {