Fix code review items: atomic qty increment, unit updatedAt, suppliers/all endpoint, SKU unique index
This commit is contained in:
@@ -225,7 +225,7 @@ export const InventoryUnitService = {
|
||||
if (!valid) throw new ValidationError(`Invalid status: "${input.status}"`)
|
||||
}
|
||||
|
||||
const updates: Record<string, unknown> = { ...input }
|
||||
const updates: Record<string, unknown> = { ...input, updatedAt: new Date() }
|
||||
if (input.purchaseCost !== undefined) updates.purchaseCost = input.purchaseCost.toString()
|
||||
|
||||
const [unit] = await db
|
||||
@@ -317,14 +317,11 @@ export const StockReceiptService = {
|
||||
})
|
||||
.returning()
|
||||
|
||||
// For non-serialized products, increment qty_on_hand
|
||||
const [product] = await db.select().from(products).where(eq(products.id, productId)).limit(1)
|
||||
if (product && !product.isSerialized) {
|
||||
await db
|
||||
.update(products)
|
||||
.set({ qtyOnHand: product.qtyOnHand + input.qty, updatedAt: new Date() })
|
||||
.where(eq(products.id, productId))
|
||||
}
|
||||
// For non-serialized products, increment qty_on_hand atomically
|
||||
await db
|
||||
.update(products)
|
||||
.set({ qtyOnHand: sql`${products.qtyOnHand} + ${input.qty}`, updatedAt: new Date() })
|
||||
.where(and(eq(products.id, productId), eq(products.isSerialized, false)))
|
||||
|
||||
return receipt
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user