update: the blog comment logic for admin
This commit is contained in:
@@ -2,6 +2,8 @@ import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { IsNull, Repository } from "typeorm";
|
||||
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { BlogCommentQueryDto } from "../DTO/blog-comment-query.dto";
|
||||
import { BlogComment } from "../entities/blog-comment.entity";
|
||||
import { CommentStatus } from "../enums/comment-status.enum";
|
||||
|
||||
@@ -35,6 +37,27 @@ export class BlogCommentsRepository extends Repository<BlogComment> {
|
||||
});
|
||||
}
|
||||
|
||||
async getAllCommentsForAdmin(queryDto: BlogCommentQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
const query = this.createQueryBuilder("blogComment")
|
||||
.leftJoin("blogComment.blog", "blog")
|
||||
.addSelect(["blog.id", "blog.title"])
|
||||
.leftJoin("blogComment.user", "user")
|
||||
.addSelect(["user.id", "user.firstName", "user.lastName"]);
|
||||
|
||||
if (queryDto.q) {
|
||||
query.andWhere("blogComment.content ILIKE :q", { q: `%${queryDto.q}%` });
|
||||
}
|
||||
|
||||
if (queryDto.status) {
|
||||
query.andWhere("blogComment.status = :status", { status: queryDto.status });
|
||||
}
|
||||
|
||||
query.orderBy("blogComment.createdAt", "DESC").skip(skip).take(limit);
|
||||
|
||||
return query.getManyAndCount();
|
||||
}
|
||||
|
||||
async findBlogCommentsByBlogId(blogId: string) {
|
||||
return this.find({
|
||||
where: { blog: { id: blogId, deletedAt: IsNull() }, status: CommentStatus.APPROVED },
|
||||
|
||||
Reference in New Issue
Block a user