mid-dev-44 wants to mergefix/product-overwrites→main
MI
mid-dev-44
1 file changed · 2 hours ago
YOUR MISSION
In a high-traffic "Edit Product" screen, users are complaining that their changes are "vanishing." If two admins edit the same product at once, the one who clicks save last wins, completely overwriting the first admin’s work without warning.
Mid~15 min
HINTS (0/3 used)
REVIEWING AS
SR
Senior Engineer
@ Amazon · Backend Platform
src / db / product.repo.ts+4−2
10
10
async function updateProduct(id: string, data: ProductUpdate) {
11
11
const { name, price, version } = data;
12
12
await db.query(
13
−
"UPDATE products SET name = $1, price = $2 WHERE id = $3",
+
14
−
[name, price, id]
+
13
+
"UPDATE products SET name = $1, price = $2, version = version + 1
+
14
+
WHERE id = $3 AND version = $4",
+
15
+
[name, price, id, version]
+
15
16
);
17
+
// BUG: What if the update failed because the version was wrong?
+
16
18
}
Click any changed line (+/−) to flag an issue · or Approve if everything looks safe