Completing Orders in 'accepted' status

Cases when to Complete an Order in 'accepted' status

Query to use

With upd as (
Update orders set status = 'complete', "updatedAt" = now()
where status = 'accepted' and "locationId" = $1 and "updatedAt" > $2 returning id)
Insert into order_logs("orderId",log,"createdAt")
Select id, '{"audit": "accepted => complete", "logId": id || '-1', "action": ["update_by: doshii_ops", "order_updated"]}',now()
from upd