找出订单替换里的 bug

来自 RESTful API 设计
Node 24 进阶 4分钟 找出 1处问题

找出这段生成的替换处理器中的丢失更新缺陷。

JavaScript
async function replaceOrder(id, input, ifMatch, db) {
  const current = await db.orders.find(id);
  if (!current) return { status: 404 };
  if (ifMatch !== `"order-${current.version}"`) {
    return { status: 412 };
  }
  const next = { id, status: input.status, version: current.version + 1 };
  await db.orders.update(id, next);
  return { status: 200, body: next };
}
在试验场中打开
报告错误