should be descendents but typeorm is broken

master
Lauren Liberda 2021-07-17 22:51:12 +02:00
parent 1f4a51f8d4
commit c1df170c6a
3 changed files with 15 additions and 0 deletions

View File

@ -18,4 +18,7 @@ export class ItemModel {
@Field((type) => [ItemModel])
children: ItemModel[];
@Field((type) => [ItemModel], { deprecationReason: 'typeorm issues' })
descendents: ItemModel[];
}

View File

@ -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);

View File

@ -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,