Spot the bug in the product update

from HTTP API design
Node 24 intermediate 4 min 1 issue to find

Find the concurrency flaw in this generated product update.

JavaScript
async function updateProduct(id, patch, db) {
  const current = await db.products.find(id);
  if (!current) return { status: 404 };
  const updated = { ...current, ...patch };
  await db.products.update(id, updated);
  return { status: 200, body: updated };
}
Open in playground
Report an error