modify bugs

This commit is contained in:
2025-07-02 22:35:23 +08:00
parent 0f8abaec7f
commit d2692e6a11
24 changed files with 82 additions and 40 deletions
+1 -1
View File
@@ -44,8 +44,8 @@ export class ContentModule {
categoryRepository: repositories.CategoryRepository,
tagRepository: repositories.TagRepository,
categoryService: services.CategoryService,
searchService: SearchService,
userRepository: UserRepository,
searchService: SearchService,
) {
return new PostService(
postRepository,
@@ -104,7 +104,7 @@ export class PostController {
@SerializeOptions({ groups: ['post-detail'] })
async show(@Param('id', new ParseUUIDPipe()) id: string) {
return this.postService.detail(id, async (qb) =>
qb.andWhere({ publishedAt: Not(IsNull()), deletedAt: Not(IsNull()) }),
qb.andWhere({ publishedAt: Not(IsNull()), deletedAt: IsNull() }),
);
}
+3 -1
View File
@@ -1,4 +1,4 @@
import { IsDefined, IsUUID } from 'class-validator';
import { ArrayMinSize, IsArray, IsDefined, IsUUID } from 'class-validator';
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
@@ -6,5 +6,7 @@ import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator
export class DeleteDto {
@IsUUID(undefined, { each: true, always: true, message: 'The ID format is incorrect' })
@IsDefined({ each: true, message: 'The ID must be specified' })
@IsArray()
@ArrayMinSize(1)
ids: string[];
}
+1 -2
View File
@@ -39,7 +39,6 @@ export class PostEntity extends BaseEntity {
@Column({ comment: '文章描述', nullable: true })
summary?: string;
@Expose()
@Expose()
@Column({ comment: '关键字', type: 'simple-array', nullable: true })
keywords?: string[];
@@ -69,7 +68,7 @@ export class PostEntity extends BaseEntity {
@Expose()
@Type(() => Date)
@DeleteDateColumn({ comment: '删除时间' })
deleteAt: Date;
deletedAt: Date;
@Expose()
commentCount: number;
+23
View File
@@ -3,7 +3,9 @@ import { ModuleRef } from '@nestjs/core';
import { CategoryEntity, CommentEntity, PostEntity, TagEntity } from '@/modules/content/entities';
import { PermissionAction, SystemRoles } from '@/modules/rbac/constants';
import { PermissionEntity, RoleEntity } from '@/modules/rbac/entities';
import { RbacResolver } from '@/modules/rbac/rbac.resolver';
import { UserEntity } from '@/modules/user/entities';
@Injectable()
export class ContentRbac implements OnModuleInit {
@@ -73,6 +75,27 @@ export class ContentRbac implements OnModuleInit {
subject: CommentEntity,
},
},
{
name: 'permission.manage',
rule: {
action: PermissionAction.MANAGE,
subject: PermissionEntity,
},
},
{
name: 'role.manage',
rule: {
action: PermissionAction.MANAGE,
subject: RoleEntity,
},
},
{
name: 'user.manage',
rule: {
action: PermissionAction.MANAGE,
subject: UserEntity,
},
},
]);
resolver.addRoles([
@@ -11,12 +11,13 @@ export class PostRepository extends BaseRepository<PostEntity> {
return this.createQueryBuilder(this.qbName)
.leftJoinAndSelect(`${this.qbName}.category`, 'category')
.leftJoinAndSelect(`${this.qbName}.tags`, 'tags')
.leftJoinAndSelect(`${this.qbName}.author`, 'author')
.addSelect((query) => {
return query
.select('COUNT(c.id)', 'count')
.from(CommentEntity, 'c')
.where(`c.post.id = ${this.qbName}.id`);
}, 'commentCount')
.loadRelationCountAndMap(`${this.qbName}.commentCOunt`, `${this.qbName}.comments`);
.loadRelationCountAndMap(`${this.qbName}.commentCount`, `${this.qbName}.comments`);
}
}
+8 -5
View File
@@ -147,8 +147,8 @@ export class PostService extends BaseService<PostEntity, PostRepository, FindPar
.getMany();
let result: PostEntity[];
if (trash) {
const directs = items.filter((item) => !isNil(item.deleteAt));
const softs = items.filter((item) => isNil(item.deleteAt));
const directs = items.filter((item) => !isNil(item.deletedAt));
const softs = items.filter((item) => isNil(item.deletedAt));
result = [
...(await this.repository.remove(directs)),
...(await this.repository.softRemove(softs)),
@@ -172,7 +172,7 @@ export class PostService extends BaseService<PostEntity, PostRepository, FindPar
.where('post.id IN (:...ids)', { ids })
.withDeleted()
.getMany();
const trashes = items.filter((item) => !isNil(item.deleteAt));
const trashes = items.filter((item) => !isNil(item.deletedAt));
await this.searchService.update(trashes);
const trashedIds = trashes.map((item) => item.id);
if (trashedIds.length < 1) {
@@ -190,7 +190,7 @@ export class PostService extends BaseService<PostEntity, PostRepository, FindPar
options: FindParams,
callback?: QueryHook<PostEntity>,
) {
const { orderBy, isPublished, category, tag, trashed, search } = options;
const { orderBy, isPublished, category, tag, trashed, search, author } = options;
if (typeof isPublished === 'boolean') {
isPublished
? qb.where({ publishedAt: Not(IsNull()) })
@@ -212,6 +212,9 @@ export class PostService extends BaseService<PostEntity, PostRepository, FindPar
if (tag) {
qb.where('tags.id = :id', { id: tag });
}
if (author) {
qb.where('author.id = :id', { id: author });
}
if (callback) {
return callback(qb);
}
@@ -252,6 +255,6 @@ export class PostService extends BaseService<PostEntity, PostRepository, FindPar
const tree = await this.categoryRepository.findDescendantsTree(root);
const flatDes = await this.categoryRepository.toFlatTrees(tree.children);
const ids = [tree.id, ...flatDes.map((item) => item.id)];
return qb.where('categoryRepository.id IN (:...ids)', { ids });
return qb.where('category.id IN (:...ids)', { ids });
}
}
@@ -48,7 +48,7 @@ export class SearchService implements OnModuleInit {
}
async search(text: string, param: SearchOption = {}): Promise<any> {
const option = { page: 1, limit: 10, trashed: SelectTrashMode.ONLY, ...param };
const option = { page: 1, limit: 10, trashed: SelectTrashMode.NONE, ...param };
const limit = isNil(option.limit) || option.limit < 1 ? 1 : option.limit;
const page = isNil(option.page) || option.page < 1 ? 1 : option.page;
let filter = ['deletedAt IS NULL'];
@@ -64,7 +64,7 @@ export class SearchService implements OnModuleInit {
.index(this.index)
.search(text, { page, limit, sort: ['updatedAt:desc', 'commentCount:desc'], filter });
return {
item: result.hits,
items: result.hits,
currentPage: result.page,
perPage: result.hitsPerPage,
totalItems: result.estimatedTotalHits,
+1 -1
View File
@@ -29,7 +29,7 @@ export async function getSearchItem(
'body',
'summary',
'commentCount',
'deleteAt',
'deletedAt',
'publishedAt',
'createdAt',
'updatedAt',