feat(inventory): implement numeric stock inventory across fullstack and improve prescription UX handoff
This commit is contained in:
1 parent
e9582430e6
commit
741365f04c
13 files changed
+177
-47
No files matched your search
@@ -433,12 +433,36 @@ export class PaymentService {
|
||||
},
|
||||
});
|
||||
|
||||
// Mark inventory reservations as CONSUMED
|
||||
// Mark inventory reservations as CONSUMED and decrement product stock
|
||||
await tx.inventoryReservation.updateMany({
|
||||
where: { orderId: transaction.orderId, status: 'ACTIVE' },
|
||||
data: { status: 'CONSUMED' },
|
||||
});
|
||||
|
||||
const orderWithItems = await tx.order.findUnique({
|
||||
where: { id: transaction.orderId },
|
||||
include: { orderItems: true },
|
||||
});
|
||||
|
||||
if (orderWithItems?.orderItems) {
|
||||
for (const item of orderWithItems.orderItems) {
|
||||
if (item.productId) {
|
||||
const updated = await tx.product.update({
|
||||
where: { id: item.productId },
|
||||
data: {
|
||||
stock: { decrement: item.quantity },
|
||||
},
|
||||
});
|
||||
if (updated.stock <= 0) {
|
||||
await tx.product.update({
|
||||
where: { id: item.productId },
|
||||
data: { stockStatus: 'OUT_OF_STOCK' },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If charity donation was made, update user's total charity
|
||||
if (
|
||||
transaction.order &&
|
||||
|
||||
Reference in new issue
Block a user