|
|
@@ -0,0 +1,32 @@
|
|
|
+import {
|
|
|
+ Injectable
|
|
|
+} from '@nestjs/common'
|
|
|
+import { In, Repository, UpdateResult } from 'typeorm'
|
|
|
+import { InjectRepository } from '@nestjs/typeorm'
|
|
|
+import { paginate, Pagination } from 'nestjs-typeorm-paginate'
|
|
|
+import { PageRequest } from '../common/dto/page-request'
|
|
|
+import { Comment } from './entities/comment.entity'
|
|
|
+
|
|
|
+@Injectable()
|
|
|
+export class CommentService {
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ @InjectRepository(Comment)
|
|
|
+ private readonly commentRepository: Repository<Comment>
|
|
|
+ ) { }
|
|
|
+
|
|
|
+
|
|
|
+ async findAll(req: PageRequest<Comment>, momentsId: number): Promise<Pagination<Comment>> {
|
|
|
+ const query = await this.commentRepository.createQueryBuilder('comment')
|
|
|
+ .where('(comment.momentsId = :momentsId and comment.rootCommentId is null) or (comment.rootCommentId in (select id from Comment where momentsId = :momentsId and rootCommentId is null))', { momentsId })
|
|
|
+
|
|
|
+ // if (req.search) {
|
|
|
+ // query.where(req.search)
|
|
|
+ // }
|
|
|
+
|
|
|
+ const options = { ...req.page }
|
|
|
+
|
|
|
+ return await paginate<Comment>(query, options)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|