fix:补充分类的存储库方法、修复分类服务没有正确添加children
This commit is contained in:
parent
dbc14c2137
commit
d30273d180
@ -13,6 +13,16 @@ export class CategoryRepository extends TreeRepository<CategoryEntity> {
|
|||||||
return this.createQueryBuilder('category').leftJoinAndSelect('category.parent', 'parent');
|
return this.createQueryBuilder('category').leftJoinAndSelect('category.parent', 'parent');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 树形结构查询
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
async findTrees(options?: FindTreeOptions) {
|
||||||
|
const roots = await this.findRoots(options);
|
||||||
|
await Promise.all(roots.map((root) => this.findDescendantsTree(root, options)));
|
||||||
|
return roots;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询顶级分类
|
* 查询顶级分类
|
||||||
* @param options
|
* @param options
|
||||||
|
@ -105,25 +105,20 @@ export class CategoryService {
|
|||||||
/**
|
/**
|
||||||
* 获取请求传入的父分类
|
* 获取请求传入的父分类
|
||||||
* @param current 当前分类的ID
|
* @param current 当前分类的ID
|
||||||
* @param parentId
|
* @param id
|
||||||
*/
|
*/
|
||||||
protected async getParent(current?: string, parentId?: string) {
|
protected async getParent(current?: string, parentId?: string) {
|
||||||
if (current === parentId) return undefined;
|
if (current === parentId) return undefined;
|
||||||
|
|
||||||
let parent: CategoryEntity | undefined;
|
let parent: CategoryEntity | undefined;
|
||||||
|
|
||||||
if (parentId !== undefined) {
|
if (parentId !== undefined) {
|
||||||
if (parentId !== null) return null;
|
if (parentId === null) return null;
|
||||||
|
|
||||||
parent = await this.repository.findOne({ where: { id: parentId } });
|
parent = await this.repository.findOne({ where: { id: parentId } });
|
||||||
|
|
||||||
if (!parent)
|
if (!parent)
|
||||||
throw new EntityNotFoundError(
|
throw new EntityNotFoundError(
|
||||||
CategoryEntity,
|
CategoryEntity,
|
||||||
`Parent category ${parentId} not exists!`,
|
`Parent category ${parentId} not exists!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user