|
@@ -9,7 +9,7 @@ import { Comment } from './entities/comment.entity'
|
|
|
import { CommentDto } from './dto/comment.dto'
|
|
import { CommentDto } from './dto/comment.dto'
|
|
|
import { LikesService } from 'src/likes/likes.service'
|
|
import { LikesService } from 'src/likes/likes.service'
|
|
|
import { Likes } from 'src/likes/entities/likes.entity'
|
|
import { Likes } from 'src/likes/entities/likes.entity'
|
|
|
-import { id, tr } from 'date-fns/locale'
|
|
|
|
|
|
|
+import { Moments } from 'src/moments/entities/moments.entity'
|
|
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
|
export class CommentService {
|
|
export class CommentService {
|
|
@@ -19,6 +19,8 @@ export class CommentService {
|
|
|
private readonly commentRepository: Repository<Comment>,
|
|
private readonly commentRepository: Repository<Comment>,
|
|
|
@InjectRepository(Likes)
|
|
@InjectRepository(Likes)
|
|
|
private readonly likesRepository: Repository<Likes>,
|
|
private readonly likesRepository: Repository<Likes>,
|
|
|
|
|
+ @InjectRepository(Moments)
|
|
|
|
|
+ private readonly momentsRepository: Repository<Moments>,
|
|
|
private readonly likesService: LikesService
|
|
private readonly likesService: LikesService
|
|
|
) { }
|
|
) { }
|
|
|
|
|
|
|
@@ -134,7 +136,10 @@ export class CommentService {
|
|
|
}
|
|
}
|
|
|
await this.commentRepository.save(list)
|
|
await this.commentRepository.save(list)
|
|
|
}
|
|
}
|
|
|
- return await this.commentRepository.save(commentDto);
|
|
|
|
|
|
|
+ const moments = await this.momentsRepository.findOneBy({ id: +commentDto.momentsId })
|
|
|
|
|
+ moments.commentNum += 1
|
|
|
|
|
+ await this.momentsRepository.save(moments)
|
|
|
|
|
+ return await this.commentRepository.save(commentDto)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public async findChildList(req: PageRequest<Comment>): Promise<Pagination<Comment>> {
|
|
public async findChildList(req: PageRequest<Comment>): Promise<Pagination<Comment>> {
|
|
@@ -169,6 +174,9 @@ export class CommentService {
|
|
|
comment.isDel = true
|
|
comment.isDel = true
|
|
|
await this.commentRepository.save(comment)
|
|
await this.commentRepository.save(comment)
|
|
|
}
|
|
}
|
|
|
|
|
+ const moments = await this.momentsRepository.findOneBy({ id: +comment.momentsId })
|
|
|
|
|
+ moments.commentNum -= 1
|
|
|
|
|
+ await this.momentsRepository.save(moments)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public async like(id: number, userId: number): Promise<void> {
|
|
public async like(id: number, userId: number): Promise<void> {
|