fix item ancestor/descendant lists
This commit is contained in:
parent
e2b0ffb7cd
commit
3cc2c73bc2
|
@ -36,14 +36,13 @@ export class ItemsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getItemAncestors(item: ItemModel): Promise<Item[]> {
|
async getItemAncestors(item: ItemModel): Promise<Item[]> {
|
||||||
const childItem = await this.itemRepository.findOneOrFail(
|
const id = this.eans.toID(item.id);
|
||||||
this.eans.toID(item.id),
|
const childItem = await this.itemRepository.findOneOrFail(id, {
|
||||||
{
|
relations: ['parent'],
|
||||||
relations: ['parent'],
|
});
|
||||||
},
|
return (await this.treeRepository.findAncestors(childItem)).filter(
|
||||||
|
(anc) => anc.id !== id,
|
||||||
);
|
);
|
||||||
// TreeRepository.findAncestors()[-1] is always the child item itself
|
|
||||||
return (await this.treeRepository.findAncestors(childItem)).slice(0, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getItemChildren(item: ItemModel): Promise<Item[]> {
|
async getItemChildren(item: ItemModel): Promise<Item[]> {
|
||||||
|
@ -55,14 +54,13 @@ export class ItemsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getItemDescendants(item: ItemModel): Promise<Item[]> {
|
async getItemDescendants(item: ItemModel): Promise<Item[]> {
|
||||||
const parentItem = await this.itemRepository.findOneOrFail(
|
const id = this.eans.toID(item.id);
|
||||||
this.eans.toID(item.id),
|
const parentItem = await this.itemRepository.findOneOrFail(id, {
|
||||||
{
|
relations: ['parent'],
|
||||||
relations: ['parent'],
|
});
|
||||||
},
|
return (await this.treeRepository.findDescendants(parentItem)).filter(
|
||||||
|
(des) => des.id !== id,
|
||||||
);
|
);
|
||||||
// TreeRepository.findDescendants()[0] is always the parent item
|
|
||||||
return (await this.treeRepository.findDescendants(parentItem)).slice(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getItemList(cursor: number = 0): Promise<PaginatedItems> {
|
async getItemList(cursor: number = 0): Promise<PaginatedItems> {
|
||||||
|
|
Loading…
Reference in a new issue