diff --git a/src/app.module.ts b/src/app.module.ts index 6f0ad48..73b2f99 100755 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -20,6 +20,7 @@ import { AddressModule } from "./modules/address/address.module"; import { AdsModule } from "./modules/ads/ads.module"; import { AnnouncementsModule } from "./modules/announcements/announcement.module"; import { AuthModule } from "./modules/auth/auth.module"; +import { BlogsModule } from "./modules/blogs/blogs.module"; import { ContactUsModule } from "./modules/contact-us/contact-us.module"; import { CriticismModule } from "./modules/criticisms/criticisms.module"; import { DanakServicesModule } from "./modules/danak-services/danak-services.module"; @@ -35,7 +36,6 @@ import { TicketsModule } from "./modules/tickets/tickets.module"; import { UploaderModule } from "./modules/uploader/uploader.module"; import { UsersModule } from "./modules/users/users.module"; import { WalletsModule } from "./modules/wallets/wallets.module"; - @Module({ imports: [ TelegrafModule.forRootAsync(telegrafConfig()), @@ -65,6 +65,7 @@ import { WalletsModule } from "./modules/wallets/wallets.module"; AdsModule, AddressModule, DashboardModule, + BlogsModule, LoggerModule, ], controllers: [], diff --git a/src/modules/blogs/controllers/blogs.controller.ts b/src/modules/blogs/controllers/blogs.controller.ts index efcdc75..a8c7cc4 100644 --- a/src/modules/blogs/controllers/blogs.controller.ts +++ b/src/modules/blogs/controllers/blogs.controller.ts @@ -86,12 +86,12 @@ export class BlogsController { return this.blogsService.createComment(paramDto.id, createCommentDto, userId); } - @ApiOperation({ summary: "Get all comments for a blog" }) + @ApiOperation({ summary: "Get all comments for a blog (admin route)" }) @AdminRoute() @PermissionsDec(PermissionEnum.BLOGS) @Get(":id/comments") - getBlogComments(@Param() paramDto: ParamDto) { - return this.blogsService.getBlogComments(paramDto.id); + getBlogCommentsForAdmin(@Param() paramDto: ParamDto) { + return this.blogsService.getBlogCommentsForAdmin(paramDto.id); } @ApiOperation({ summary: "Update the status of a comment (admin route)" }) diff --git a/src/modules/blogs/providers/blogs.service.ts b/src/modules/blogs/providers/blogs.service.ts index 7acca12..5f90889 100644 --- a/src/modules/blogs/providers/blogs.service.ts +++ b/src/modules/blogs/providers/blogs.service.ts @@ -150,7 +150,8 @@ export class BlogsService { async getBlogById(id: string) { const blog = await this.findBlogById(id); - return { blog }; + const comments = await this.blogCommentsRepository.findBlogCommentsByBlogId(id); + return { blog, comments }; } //*********************************** */ @@ -208,8 +209,8 @@ export class BlogsService { } //*********************************** */ - async getBlogComments(blogId: string) { - const comments = await this.blogCommentsRepository.findAllByBlogId(blogId); + async getBlogCommentsForAdmin(blogId: string) { + const comments = await this.blogCommentsRepository.findBlogCommentsForAdmin(blogId); return { comments }; } diff --git a/src/modules/blogs/repositories/blog-comments.repository.ts b/src/modules/blogs/repositories/blog-comments.repository.ts index b270526..8aee641 100644 --- a/src/modules/blogs/repositories/blog-comments.repository.ts +++ b/src/modules/blogs/repositories/blog-comments.repository.ts @@ -1,6 +1,6 @@ import { Injectable } from "@nestjs/common"; import { InjectRepository } from "@nestjs/typeorm"; -import { Repository } from "typeorm"; +import { IsNull, Repository } from "typeorm"; import { BlogComment } from "../entities/blog-comment.entity"; import { CommentStatus } from "../enums/comment-status.enum"; @@ -17,10 +17,39 @@ export class BlogCommentsRepository extends Repository { }); } - async findAllByBlogId(blogId: string) { + async findBlogCommentsForAdmin(blogId: string) { return this.find({ - where: { blog: { id: blogId }, status: CommentStatus.APPROVED }, + where: { blog: { id: blogId, deletedAt: IsNull() } }, order: { createdAt: "DESC" }, + relations: { + user: true, + }, + select: { + id: true, + title: true, + content: true, + createdAt: true, + status: true, + user: { id: true, firstName: true, lastName: true }, + }, + }); + } + + async findBlogCommentsByBlogId(blogId: string) { + return this.find({ + where: { blog: { id: blogId, deletedAt: IsNull() }, status: CommentStatus.APPROVED }, + order: { createdAt: "DESC" }, + relations: { + user: true, + }, + select: { + id: true, + title: true, + content: true, + createdAt: true, + status: true, + user: { id: true, firstName: true, lastName: true }, + }, }); } }