handle some performance for app
This commit is contained in:
@@ -39,7 +39,15 @@ class ProductController extends SuperController
|
||||
}])->get();
|
||||
|
||||
// Prepare the response
|
||||
$user['rows'] = $products;
|
||||
$user['rows'] = $products->map(function ($product) {
|
||||
$product->unit = self::productQuantityUnit([
|
||||
'unit' => $product->unit ?? null,
|
||||
'direct_price' => $product->direct_price ?? null,
|
||||
'group_type' => $product->group_type ?? null,
|
||||
]);
|
||||
|
||||
return $product;
|
||||
});
|
||||
|
||||
return response()->json($user);
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ class WalletController extends Controller
|
||||
$this->applyMetalTypeTransactionTitle($record);
|
||||
$this->applyProductTransactionTitle($record);
|
||||
$this->applyProductOrderDisplayFields($record);
|
||||
$this->applyProductTransactionUnit($record);
|
||||
}
|
||||
|
||||
return response()->json($records);
|
||||
@@ -454,10 +455,28 @@ class WalletController extends Controller
|
||||
}
|
||||
|
||||
if (!empty($record->wallet?->product)) {
|
||||
$record->unit = $record->wallet->product->unit ?: 'عدد';
|
||||
$record->unit = self::productQuantityUnit([
|
||||
'unit' => $record->wallet->product->unit ?? null,
|
||||
'direct_price' => $record->wallet->product->direct_price ?? null,
|
||||
'group_type' => $record->wallet->product->group_type ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function applyProductTransactionUnit($record): void
|
||||
{
|
||||
$product = $record->wallet->product ?? $record->product ?? null;
|
||||
if (!$product) {
|
||||
return;
|
||||
}
|
||||
|
||||
$record->unit = self::productQuantityUnit([
|
||||
'unit' => $product->unit ?? null,
|
||||
'direct_price' => $product->direct_price ?? null,
|
||||
'group_type' => $product->group_type ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function isProductWalletTransaction($record): bool
|
||||
{
|
||||
return !empty($record->wallet?->product);
|
||||
|
||||
Reference in New Issue
Block a user