fix(orders): resolve 500 error in order creation by fixing orderItems payload and prevent premature wallet deduction
Deploy Canina / deploy (push) Successful in 1m43s
Deploy Canina / deploy (push) Successful in 1m43s
This commit is contained in:
1 parent
2e217ebe3d
commit
1aa9d6e34d
2 files changed
+34
-70
No files matched your search
@@ -134,8 +134,6 @@ export class OrdersService {
|
||||
const orderItemsData: Array<{
|
||||
productId: string;
|
||||
quantity: number;
|
||||
unitPrice: number;
|
||||
totalPrice: number;
|
||||
}> = [];
|
||||
|
||||
for (const item of createOrderDto.items) {
|
||||
@@ -147,8 +145,6 @@ export class OrdersService {
|
||||
orderItemsData.push({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
unitPrice: Number(unitPrice),
|
||||
totalPrice: Number(totalItemPrice),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -244,7 +240,6 @@ export class OrdersService {
|
||||
|
||||
const isOnline = createOrderDto.paymentMethod === 'online';
|
||||
const initialStatus = isOnline ? 'pending_payment' : 'processing';
|
||||
const reservationExpiry = new Date(Date.now() + 15 * 60 * 1000); // 15 minutes hold
|
||||
|
||||
const createdOrder = await this.prisma.order.create({
|
||||
data: {
|
||||
@@ -261,20 +256,11 @@ export class OrdersService {
|
||||
orderItems: {
|
||||
create: orderItemsData,
|
||||
},
|
||||
inventoryReservations: {
|
||||
create: orderItemsData.map((item) => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
expiresAt: reservationExpiry,
|
||||
status: isOnline ? 'ACTIVE' : 'CONSUMED',
|
||||
})),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
orderItems: {
|
||||
include: { product: true },
|
||||
},
|
||||
inventoryReservations: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user