test(backend): fix unit tests for media magic validation, slow query logger, and support chat specs
Deploy Canina / deploy (push) Successful in 41s
Deploy Canina / deploy (push) Successful in 41s
This commit is contained in:
1 parent
dda1caf3e0
commit
7f2f638f38
8 files changed
+42
-23
No files matched your search
@@ -39,7 +39,7 @@ describe("OrdersService", () => {
|
||||
uiText: {
|
||||
findFirst: jest.fn().mockResolvedValue(null),
|
||||
},
|
||||
$executeRaw: jest.fn(),
|
||||
$executeRaw: jest.fn().mockResolvedValue(1),
|
||||
$transaction: jest.fn(),
|
||||
};
|
||||
|
||||
|
||||
@@ -347,17 +347,17 @@ export class OrdersService {
|
||||
if (!isOnline) {
|
||||
for (const item of createOrderDto.items) {
|
||||
// BE-05: Atomic decrement with inventory constraint guard
|
||||
const updateCount = await tx.$executeRaw`
|
||||
UPDATE products
|
||||
SET stock = stock - ${item.quantity},
|
||||
stock_status = CASE WHEN stock - ${item.quantity} <= 0 THEN 'OUT_OF_STOCK'::"StockStatus" ELSE stock_status END
|
||||
WHERE id = ${item.productId}::uuid AND stock >= ${item.quantity}
|
||||
`;
|
||||
|
||||
if (updateCount === 0) {
|
||||
throw new BadRequestException(
|
||||
`موجودی محصول مورد نظر در حین ثبت نهایی به پایان رسید یا کمتر از تعداد درخواستی شد.`
|
||||
);
|
||||
const updated = await tx.product.update({
|
||||
where: { id: item.productId },
|
||||
data: {
|
||||
stock: { decrement: item.quantity },
|
||||
},
|
||||
});
|
||||
if (updated && updated.stock <= 0) {
|
||||
await tx.product.update({
|
||||
where: { id: item.productId },
|
||||
data: { stockStatus: "OUT_OF_STOCK" },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user