should be descendents but typeorm is broken
This commit is contained in:
parent
1f4a51f8d4
commit
c1df170c6a
|
@ -18,4 +18,7 @@ export class ItemModel {
|
|||
|
||||
@Field((type) => [ItemModel])
|
||||
children: ItemModel[];
|
||||
|
||||
@Field((type) => [ItemModel], { deprecationReason: 'typeorm issues' })
|
||||
descendents: ItemModel[];
|
||||
}
|
||||
|
|
|
@ -30,6 +30,11 @@ export class ItemsResolver {
|
|||
return this.itemsService.getItemChildren(item);
|
||||
}
|
||||
|
||||
@ResolveField()
|
||||
async descendents(@Parent() item: ItemModel) {
|
||||
return this.itemsService.getItemDescendents(item);
|
||||
}
|
||||
|
||||
@Mutation((returns) => ItemModel)
|
||||
async createItem(@Args('itemData') itemData: NewItemInput) {
|
||||
return this.itemsService.createItem(itemData);
|
||||
|
|
|
@ -36,6 +36,13 @@ export class ItemsService {
|
|||
});
|
||||
}
|
||||
|
||||
async getItemDescendents(item: ItemModel): Promise<Item[]> {
|
||||
const parentItem = await this.itemRepository.findOneOrFail(item.id, {
|
||||
relations: ['parent'],
|
||||
});
|
||||
return this.treeRepository.findDescendants(parentItem);
|
||||
}
|
||||
|
||||
async createItem(input: NewItemInput): Promise<Item> {
|
||||
const item = this.itemRepository.create({
|
||||
...input,
|
||||
|
|
Loading…
Reference in a new issue