|
|
@@ -8,6 +8,7 @@ import { PageRequest } from '../common/dto/page-request'
|
|
|
import { Comment } from './entities/comment.entity'
|
|
|
import { CommentDto } from './dto/comment.dto'
|
|
|
import { LikesService } from 'src/likes/likes.service'
|
|
|
+import { string } from 'yup'
|
|
|
|
|
|
@Injectable()
|
|
|
export class CommentService {
|
|
|
@@ -22,6 +23,7 @@ export class CommentService {
|
|
|
async findAll(req: PageRequest<Comment>): Promise<Pagination<Comment>> {
|
|
|
const query = await this.commentRepository.createQueryBuilder()
|
|
|
.where('comment.isDel = false')
|
|
|
+ .andWhere('rootCommentId is null')
|
|
|
|
|
|
if (req.search) {
|
|
|
const searchOptions = req.search as FindManyOptions<Comment>;
|
|
|
@@ -49,14 +51,19 @@ export class CommentService {
|
|
|
|
|
|
const { items, meta } = page;
|
|
|
const rootMap = new Map<number, Comment>()
|
|
|
+ const ids: number[] = []
|
|
|
|
|
|
items.forEach(comment => {
|
|
|
- if (!Boolean(comment.rootCommentId)) {
|
|
|
- rootMap.set(comment.id, comment)
|
|
|
- }
|
|
|
+ rootMap.set(comment.id, comment)
|
|
|
+ ids.push(comment.id)
|
|
|
})
|
|
|
|
|
|
- items.forEach(comment => {
|
|
|
+ const childList = await this.commentRepository.createQueryBuilder()
|
|
|
+ .where({
|
|
|
+ id: In(ids),
|
|
|
+ }).getMany();
|
|
|
+
|
|
|
+ childList.forEach(comment => {
|
|
|
if (Boolean(comment.rootCommentId)) {
|
|
|
const root = rootMap.get(comment.rootCommentId)
|
|
|
if (root.hasOwnProperty('childList')) {
|