in warehouse/src/on_order_events/main.py [0:0]
def delete_products(order_id: str, products: Optional[list] = None) -> None:
"""
Delete products from the DynamoDB table
"""
count = 0
with table.batch_writer() as batch:
# If no list of 'products' is specified, deleted all products for
# that item.
for product in products or get_products(order_id):
# Skip metadata key
if product["productId"] == METADATA_KEY:
continue
count += 1
batch.delete_item(Key={
"orderId": order_id,
"productId": product["productId"]
})
logger.debug({
"message": "Deleting product {} for order {}".format(
product["productId"], order_id
),
"operation": "delete",
"product": product,
"orderId": order_id
})
logger.info({
"message": "Deleting {} products for order {}".format(
count, order_id
),
"operation": "delete",
"orderId": order_id,
"productCount": count
})