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 all extension comments

Yevhenii Kulisidibcfb59326998
diff --git a/src/marketplace/comments/comments.controller.ts b/src/marketplace/comments/comments.controller.ts
index 7f64958d1..4e1faa04f 100644
--- a/src/marketplace/comments/comments.controller.ts
+++ b/src/marketplace/comments/comments.controller.ts
@@ -1,6 +1,32 @@
-import { Controller } from '@nestjs/common'
-import { ApiTags } from '@nestjs/swagger'
+import { Controller, Get, Query } from '@nestjs/common'
+import { ApiQuery, ApiTags } from '@nestjs/swagger'
+import { CommentsService } from './comments.service'
+import { GetCommentsQueryDto } from './dtos/queries/get-comments.dto'
+import { Comment } from './entities/comment.entity'
@ApiTags('comments')
@Controller('comments')
-export class CommentsController {}
+export class CommentsController {
+ constructor(private readonly commentsService: CommentsService) {}
+
+ @Get()
+ @ApiQuery({ name: 'offset', required: false, type: String })
+ @ApiQuery({ name: 'limit', required: false, type: String })
+ @ApiQuery({ name: 'extensionId', required: false, type: String })
+ @ApiQuery({ name: 'userId', required: false, type: String })
+ async getComments(@Query() queries: GetCommentsQueryDto): Promise<{
+ comments: Comment[]
+ count: number
+ }> {
+ const [comments, count] = await this.commentsService.findAndCount({
+ where: {
+ ...(queries.extensionId && { extensionId: queries.extensionId }),
+ ...(queries.userId && { userId: queries.userId }),
+ },
+ skip: queries.offset || 0,
+ take: queries.limit || 25,
+ })
+
+ return { comments, count }
+ }
+}
diff --git a/src/marketplace/comments/comments.service.ts b/src/marketplace/comments/comments.service.ts
index 756071de7..220e25f50 100644
--- a/src/marketplace/comments/comments.service.ts
+++ b/src/marketplace/comments/comments.service.ts
@@ -1,4 +1,17 @@
import { Injectable } from '@nestjs/common'
+import { InjectRepository } from '@nestjs/typeorm'
+import { FindManyOptions, Repository } from 'typeorm'
+import { Comment } from './entities/comment.entity'
@Injectable()
-export class CommentsService {}
+export class CommentsService {
+ constructor(
+ @InjectRepository(Comment) private commentsRepository: Repository<Comment>,
+ ) {}
+
+ async findAndCount(
+ options: FindManyOptions<Comment>,
+ ): Promise<[Comment[], number]> {
+ return await this.commentsRepository.findAndCount({ ...options })
+ }
+}
diff --git a/src/marketplace/comments/dtos/queries/get-comments.dto.ts b/src/marketplace/comments/dtos/queries/get-comments.dto.ts
new file mode 100644
index 000000000..0ac8ea272
--- /dev/null
+++ b/src/marketplace/comments/dtos/queries/get-comments.dto.ts
@@ -0,0 +1,19 @@
+import { IsNumberString, IsOptional } from 'class-validator'
+
+export class GetCommentsQueryDto {
+ @IsNumberString()
+ @IsOptional()
+ offset?: number
+
+ @IsNumberString()
+ @IsOptional()
+ limit?: number
+
+ @IsNumberString()
+ @IsOptional()
+ extensionId?: number
+
+ @IsNumberString()
+ @IsOptional()
+ userId?: number
+}