should be descendents but typeorm is broken

This commit is contained in:
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]) @Field((type) => [ItemModel])
children: 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); return this.itemsService.getItemChildren(item);
} }
@ResolveField()
async descendents(@Parent() item: ItemModel) {
return this.itemsService.getItemDescendents(item);
}
@Mutation((returns) => ItemModel) @Mutation((returns) => ItemModel)
async createItem(@Args('itemData') itemData: NewItemInput) { async createItem(@Args('itemData') itemData: NewItemInput) {
return this.itemsService.createItem(itemData); 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> { async createItem(input: NewItemInput): Promise<Item> {
const item = this.itemRepository.create({ const item = this.itemRepository.create({
...input, ...input,