item deleting

master
Lauren Liberda 2021-07-29 02:12:46 +02:00
parent 88eb19a9ae
commit 25401575e1
2 changed files with 15 additions and 0 deletions

View File

@ -57,4 +57,9 @@ export class ItemsResolver {
async createItem(@Args('itemData') itemData: NewItemInput) {
return this.itemsService.createItem(itemData);
}
@Mutation((returns) => ItemModel)
async deleteItem(@Args('id', { type: () => ID }) itemId: string) {
return this.itemsService.deleteItem(itemId);
}
}

View File

@ -117,4 +117,14 @@ export class ItemsService {
return item;
}
async deleteItem(id: string) {
const item = await this.itemRepository.findOne(this.eans.toID(id));
if (!item) {
return null;
}
// will fail if item has children
await this.itemRepository.remove(item);
return item;
}
}