mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-20 07:28:20 +00:00
fix: for comment and thread custom repository issue
This commit is contained in:
parent
8489b5355d
commit
45c45f05d3
5 changed files with 51 additions and 37 deletions
|
|
@ -9,10 +9,11 @@ import { User } from 'src/entities/user.entity';
|
|||
import { Organization } from 'src/entities/organization.entity';
|
||||
import { AppVersion } from 'src/entities/app_version.entity';
|
||||
import { CommentUsers } from 'src/entities/comment_user.entity';
|
||||
import { Comment } from 'src/entities/comment.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [CommentController],
|
||||
imports: [TypeOrmModule.forFeature([CommentRepository, CommentUsers, AppVersion, User, Organization]), CaslModule],
|
||||
providers: [CommentService, EmailService],
|
||||
imports: [TypeOrmModule.forFeature([Comment, CommentUsers, AppVersion, User, Organization]), CaslModule],
|
||||
providers: [CommentService, EmailService, CommentRepository],
|
||||
})
|
||||
export class CommentModule {}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ import { CaslModule } from '../casl/casl.module';
|
|||
import { ThreadController } from '../../controllers/thread.controller';
|
||||
import { ThreadService } from '../../services/thread.service';
|
||||
import { ThreadRepository } from '../../repositories/thread.repository';
|
||||
import { Thread } from 'src/entities/thread.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([ThreadRepository]), CaslModule],
|
||||
imports: [TypeOrmModule.forFeature([Thread]), CaslModule],
|
||||
controllers: [ThreadController],
|
||||
providers: [ThreadService],
|
||||
providers: [ThreadService, ThreadRepository],
|
||||
})
|
||||
export class ThreadModule {}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,38 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Comment } from '../entities/comment.entity';
|
||||
import { CreateCommentDto, UpdateCommentDto } from '../dto/comment.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CommentRepository extends Repository<Comment> {
|
||||
constructor(
|
||||
@InjectRepository(Comment)
|
||||
private commentRepository: Repository<Comment>
|
||||
) {
|
||||
super(commentRepository.target, commentRepository.manager, commentRepository.queryRunner);
|
||||
}
|
||||
|
||||
public async createComment(
|
||||
createCommentDto: CreateCommentDto,
|
||||
userId: string,
|
||||
organizationId: string
|
||||
): Promise<Comment> {
|
||||
const { comment, threadId, appVersionsId } = createCommentDto;
|
||||
|
||||
const _comment = new Comment();
|
||||
_comment.comment = comment;
|
||||
_comment.threadId = threadId;
|
||||
_comment.userId = userId;
|
||||
_comment.organizationId = organizationId;
|
||||
_comment.appVersionsId = appVersionsId;
|
||||
|
||||
await _comment.save();
|
||||
return _comment;
|
||||
const _comment = this.commentRepository.create({
|
||||
comment,
|
||||
threadId,
|
||||
userId,
|
||||
organizationId,
|
||||
appVersionsId,
|
||||
});
|
||||
return this.commentRepository.save(_comment);
|
||||
}
|
||||
|
||||
public async editComment(updateCommentDto: UpdateCommentDto, editedComment: Comment): Promise<Comment> {
|
||||
const { comment, threadId } = updateCommentDto;
|
||||
|
||||
editedComment.comment = comment;
|
||||
editedComment.threadId = threadId;
|
||||
await editedComment.save();
|
||||
|
||||
return editedComment;
|
||||
return this.commentRepository.save(editedComment);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Thread } from '../entities/thread.entity';
|
||||
import { CreateThreadDto, UpdateThreadDto } from '../dto/thread.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ThreadRepository extends Repository<Thread> {
|
||||
constructor(
|
||||
@InjectRepository(Thread)
|
||||
private threadRepository: Repository<Thread>
|
||||
) {
|
||||
super(threadRepository.target, threadRepository.manager, threadRepository.queryRunner);
|
||||
}
|
||||
|
||||
public async createThread(createThreadDto: CreateThreadDto, userId: string, organizationId: string): Promise<Thread> {
|
||||
const { x, y, appId, appVersionsId, pageId } = createThreadDto;
|
||||
|
||||
const thread = new Thread();
|
||||
thread.x = x;
|
||||
thread.y = y;
|
||||
thread.appId = appId;
|
||||
thread.userId = userId;
|
||||
thread.organizationId = organizationId;
|
||||
thread.appVersionsId = appVersionsId;
|
||||
thread.pageId = pageId;
|
||||
const thread = this.threadRepository.create({
|
||||
x,
|
||||
y,
|
||||
appId,
|
||||
userId,
|
||||
organizationId,
|
||||
appVersionsId,
|
||||
pageId,
|
||||
});
|
||||
|
||||
return await thread.save();
|
||||
return await this.threadRepository.save(thread);
|
||||
}
|
||||
|
||||
public async editThread(updateThreadDto: UpdateThreadDto, editedThread: Thread): Promise<Thread> {
|
||||
|
|
@ -24,8 +35,7 @@ export class ThreadRepository extends Repository<Thread> {
|
|||
editedThread.x = x;
|
||||
editedThread.y = y;
|
||||
editedThread.isResolved = isResolved;
|
||||
await editedThread.save();
|
||||
|
||||
return editedThread;
|
||||
return await this.threadRepository.save(editedThread);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ import { CommentUsers } from 'src/entities/comment_user.entity';
|
|||
@Injectable()
|
||||
export class CommentService {
|
||||
constructor(
|
||||
@InjectRepository(CommentRepository)
|
||||
private commentRepository: CommentRepository,
|
||||
private readonly commentRepository: CommentRepository,
|
||||
@InjectRepository(AppVersion)
|
||||
private appVersionsRepository: Repository<AppVersion>,
|
||||
@InjectRepository(User)
|
||||
|
|
@ -65,9 +64,8 @@ export class CommentService {
|
|||
}
|
||||
|
||||
public async getComments(threadId: string, appVersionsId: string): Promise<Comment[]> {
|
||||
return await
|
||||
this._dataSource.
|
||||
createQueryBuilder(Comment, 'comment')
|
||||
return await this._dataSource
|
||||
.createQueryBuilder(Comment, 'comment')
|
||||
.innerJoin('comment.user', 'user')
|
||||
.addSelect(['user.id', 'user.firstName', 'user.lastName'])
|
||||
.andWhere('comment.threadId = :threadId', {
|
||||
|
|
@ -99,9 +97,8 @@ export class CommentService {
|
|||
appVersionsId: string,
|
||||
pageId: string
|
||||
): Promise<Comment[]> {
|
||||
const comments = await
|
||||
this._dataSource.
|
||||
createQueryBuilder(Comment, 'comment')
|
||||
const comments = await this._dataSource
|
||||
.createQueryBuilder(Comment, 'comment')
|
||||
.innerJoin('comment.user', 'user')
|
||||
.addSelect(['user.id', 'user.firstName', 'user.lastName'])
|
||||
.innerJoin('comment.thread', 'thread')
|
||||
|
|
|
|||
Loading…
Reference in a new issue