Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

added route for getting extension comment

Yevhenii Kulisidi7306b92bc2fe
diff --git a/src/marketplace/comments/comments.controller.ts b/src/marketplace/comments/comments.controller.ts
index 4e1faa04f..24bd2d076 100644
--- a/src/marketplace/comments/comments.controller.ts
+++ b/src/marketplace/comments/comments.controller.ts
@@ -1,6 +1,13 @@
-import { Controller, Get, Query } from '@nestjs/common'
-import { ApiQuery, ApiTags } from '@nestjs/swagger'
+import {
+ Controller,
+ Get,
+ NotFoundException,
+ Param,
+ Query,
+} from '@nestjs/common'
+import { ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'
import { CommentsService } from './comments.service'
+import { GetCommentParamDto } from './dtos/params/get-comment.dto'
import { GetCommentsQueryDto } from './dtos/queries/get-comments.dto'
import { Comment } from './entities/comment.entity'
@@ -29,4 +36,18 @@ export class CommentsController {
return { comments, count }
}
+
+ @Get(':commentId')
+ @ApiParam({ name: 'commentId', required: true, type: String })
+ async getComment(@Param() params: GetCommentParamDto): Promise<Comment> {
+ const comment = await this.commentsService.findOne({
+ where: { id: params.commentId },
+ })
+
+ if (!comment) {
+ throw new NotFoundException('Comment not found.')
+ }
+
+ return comment
+ }
}
diff --git a/src/marketplace/comments/comments.service.ts b/src/marketplace/comments/comments.service.ts
index 220e25f50..16d9972ba 100644
--- a/src/marketplace/comments/comments.service.ts
+++ b/src/marketplace/comments/comments.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
-import { FindManyOptions, Repository } from 'typeorm'
+import { FindManyOptions, FindOneOptions, Repository } from 'typeorm'
import { Comment } from './entities/comment.entity'
@Injectable()
@@ -14,4 +14,8 @@ export class CommentsService {
): Promise<[Comment[], number]> {
return await this.commentsRepository.findAndCount({ ...options })
}
+
+ async findOne(options: FindOneOptions<Comment>): Promise<Comment> {
+ return await this.commentsRepository.findOne({ ...options })
+ }
}
diff --git a/src/marketplace/comments/dtos/params/get-comment.dto.ts b/src/marketplace/comments/dtos/params/get-comment.dto.ts
new file mode 100644
index 000000000..ebf2335b2
--- /dev/null
+++ b/src/marketplace/comments/dtos/params/get-comment.dto.ts
@@ -0,0 +1,6 @@
+import { IsNumberString } from 'class-validator'
+
+export class GetCommentParamDto {
+ @IsNumberString()
+ commentId: string
+}