show old approved posts too - api

This commit is contained in:
saparatayev 2022-11-23 12:10:57 +05:00
parent 108f9528d2
commit 1ee9712556
2 changed files with 15 additions and 6 deletions

View File

@ -50,7 +50,8 @@ class ProductsAPIController extends Controller
'measure.translations:locale,model_id,attribute_data', 'measure.translations:locale,model_id,attribute_data',
'currency.translations:locale,model_id,attribute_data' 'currency.translations:locale,model_id,attribute_data'
]) ])
->approvedAndFreshEndDate() // ->approvedAndFreshEndDate()
->approved()
->orderBy('ends_at', $sortOrder); ->orderBy('ends_at', $sortOrder);
if($categoryId) { // fetch offers by the category of the product if($categoryId) { // fetch offers by the category of the product
@ -64,7 +65,8 @@ class ProductsAPIController extends Controller
'measure.translations:locale,model_id,attribute_data', 'measure.translations:locale,model_id,attribute_data',
'currency.translations:locale,model_id,attribute_data' 'currency.translations:locale,model_id,attribute_data'
]) ])
->approvedAndFreshEndDate() // ->approvedAndFreshEndDate()
->approved()
->orderBy('ends_at', $sortOrder); ->orderBy('ends_at', $sortOrder);
} else { } else {
$query = null; $query = null;
@ -87,7 +89,8 @@ class ProductsAPIController extends Controller
'measure.translations:locale,model_id,attribute_data', 'measure.translations:locale,model_id,attribute_data',
'currency.translations:locale,model_id,attribute_data' 'currency.translations:locale,model_id,attribute_data'
]) ])
->approvedAndFreshEndDate() // ->approvedAndFreshEndDate()
->approved()
->orderBy('ends_at', $sortOrder); ->orderBy('ends_at', $sortOrder);
} else { } else {
$query = null; $query = null;
@ -133,7 +136,7 @@ class ProductsAPIController extends Controller
'vendor:id,name,surname,email,username' 'vendor:id,name,surname,email,username'
])->find($id); ])->find($id);
if ($data && $data->status == 'approved' && $data->ends_at >= \Carbon\Carbon::now()){ if ($data && $data->status == 'approved' /*&& $data->ends_at >= \Carbon\Carbon::now()*/){
return response()->json($data, 200); return response()->json($data, 200);
} else { } else {
return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);

View File

@ -84,13 +84,19 @@ class Product extends Model
return $query->where('status', 'approved')->where('ends_at','>=',\DB::raw('curdate()')); return $query->where('status', 'approved')->where('ends_at','>=',\DB::raw('curdate()'));
} }
public function scopeApproved($query) {
return $query->where('status', 'approved');
}
public function scopeSearched($query, $locale, $queryString) { public function scopeSearched($query, $locale, $queryString) {
if($locale == 'tm') { if($locale == 'tm') {
$query = $query->approvedAndFreshEndDate() // $query = $query->approvedAndFreshEndDate()
$query = $query->approved()
->where('name', 'like', "%${queryString}%"); ->where('name', 'like', "%${queryString}%");
} else { } else {
$query = $query->approvedAndFreshEndDate() // $query = $query->approvedAndFreshEndDate()
$query = $query->approved()
->whereHas('translations', function ($innerQuery) use ($locale, $queryString) { ->whereHas('translations', function ($innerQuery) use ($locale, $queryString) {
$innerQuery->where('locale', $locale)->where('attribute_data', 'like', "%${queryString}%"); $innerQuery->where('locale', $locale)->where('attribute_data', 'like', "%${queryString}%");
}); });