Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ipcMain.handle("pos/createSale", (_event, payload) => { | ||
| const { items, discount, taxRate, paymentMethod, paidAmount, customerId, userId } = payload; | ||
| const subtotal = items.reduce((acc, item) => acc + item.price * item.quantity, 0); | ||
| const discountValue = discount || 0; | ||
| const taxValue = (subtotal - discountValue) * taxRate; | ||
| const total = subtotal - discountValue + taxValue; | ||
| const changeAmount = paidAmount - total; | ||
|
|
||
| const insertSale = db.prepare( | ||
| `INSERT INTO sales (customerId, total, discount, tax, paymentMethod, paidAmount, changeAmount, userId) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?)` | ||
| ); | ||
| const saleId = insertSale.run(customerId || null, total, discountValue, taxValue, paymentMethod, paidAmount, changeAmount, userId).lastInsertRowid; | ||
|
|
There was a problem hiding this comment.
Insert sale outside transaction allows partial writes
The sale header is inserted before the transaction that writes sale_items and updates stock. If any item insert or stock update fails (e.g., due to an invalid product id or a constraint error), the transaction rolls back only the item operations while the already-inserted sale row remains committed. This leaves a sale record without line items and without stock adjustments, which will corrupt totals and reports. Consider moving the INSERT INTO sales into the same transaction as the item/stock updates so the entire sale is atomic.
Useful? React with 👍 / 👎.
Summary
pos-appworkspace containing an offline barber POS built with React, TypeScript, Tailwind CSS, and ElectronTesting
https://chatgpt.com/codex/tasks/task_b_68fc5a41bae08320a28cbe6f1a84ffd7