add test case

This commit is contained in:
2025-05-27 14:07:54 +08:00
parent 1cfeb1f22e
commit a6dcfce339
7 changed files with 243 additions and 48 deletions
+1
View File
@@ -11,4 +11,5 @@ export const database = (): TypeOrmModuleOptions => ({
database: '3r',
synchronize: true,
autoLoadEntities: true,
timezone: '+08:00',
});
+2 -1
View File
@@ -6,6 +6,7 @@ import {
Entity,
JoinTable,
ManyToMany,
ManyToOne,
OneToMany,
PrimaryColumn,
Relation,
@@ -67,7 +68,7 @@ export class PostEntity extends BaseEntity {
commentCount: number;
@Expose()
@OneToMany(() => CategoryEntity, (category) => category.posts, {
@ManyToOne(() => CategoryEntity, (category) => category.posts, {
nullable: true,
onDelete: 'SET NULL',
})
@@ -10,11 +10,9 @@ import {
QueryCommentTreeDto,
} from '@/modules/content/dtos/comment.dto';
import { CommentEntity } from '@/modules/content/entities/comment.entity';
import { CommentRepository, PostRepository } from '@/modules/content/repositories';
import { treePaginate } from '@/modules/database/utils';
import { CommentRepository } from '../repositories/comment.repository';
import { PostRepository } from '../repositories/post.repository';
@Injectable()
export class CommentService {
constructor(
@@ -82,7 +80,7 @@ export class CommentService {
}
parent = await this.repository.findOne({
where: { id },
relations: ['parent', 'children'],
relations: ['parent', 'children', 'post'],
});
if (!parent) {
throw new EntityNotFoundError(CommentEntity, `Parent Comment ${id} not found`);