updated apis
This commit is contained in:
@@ -147,49 +147,46 @@ class LegalOpinionApiController extends Controller
|
||||
$current = LegalOpinion::find($id);
|
||||
|
||||
if (!$current) {
|
||||
return $this->failed([], [
|
||||
'title' => 'خطا',
|
||||
'message' => 'نظریه قانونی مورد نظر یافت نشد.'
|
||||
], 404);
|
||||
return $this->failed([], ['title' => 'خطا', 'message' => 'نظریه قانونی مورد نظر یافت نشد.'], 404);
|
||||
}
|
||||
|
||||
$previousItem = LegalOpinion::where(function ($query) use ($current) {
|
||||
if ($current->opinion_date) {
|
||||
$query->where('opinion_date', '<', $current->opinion_date)
|
||||
->orWhere(function ($subQuery) use ($current) {
|
||||
$subQuery->where('opinion_date', '=', $current->opinion_date)
|
||||
->where('id', '<', $current->id);
|
||||
});
|
||||
$query->where('opinion_date', '<', $current->opinion_date)->orWhere(function ($subQuery) use ($current) {
|
||||
$subQuery->where('opinion_date', '=', $current->opinion_date)->where('id', '<', $current->id);
|
||||
});
|
||||
} else {
|
||||
$query->whereNull('opinion_date')->where('id', '<', $current->id);
|
||||
}
|
||||
})
|
||||
->orderBy('opinion_date', 'desc')
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
})->orderBy('opinion_date', 'desc')->orderBy('id', 'desc')->first();
|
||||
|
||||
$nextItem = LegalOpinion::where(function ($query) use ($current) {
|
||||
if ($current->opinion_date) {
|
||||
$query->where('opinion_date', '>', $current->opinion_date)
|
||||
->orWhere(function ($subQuery) use ($current) {
|
||||
$subQuery->where('opinion_date', '=', $current->opinion_date)
|
||||
->where('id', '>', $current->id);
|
||||
});
|
||||
$query->where('opinion_date', '>', $current->opinion_date)->orWhere(function ($subQuery) use ($current) {
|
||||
$subQuery->where('opinion_date', '=', $current->opinion_date)->where('id', '>', $current->id);
|
||||
});
|
||||
} else {
|
||||
$query->whereNotNull('opinion_date')
|
||||
->orWhere(function ($subQuery) use ($current) {
|
||||
$subQuery->whereNull('opinion_date')->where('id', '>', $current->id);
|
||||
});
|
||||
$query->whereNotNull('opinion_date')->orWhere(function ($subQuery) use ($current) {
|
||||
$subQuery->whereNull('opinion_date')->where('id', '>', $current->id);
|
||||
});
|
||||
}
|
||||
})
|
||||
->orderBy('opinion_date', 'asc')
|
||||
->orderBy('id', 'asc')
|
||||
->first();
|
||||
})->orderBy('opinion_date', 'asc')->orderBy('id', 'asc')->first();
|
||||
|
||||
// Apply format and add Notes
|
||||
$formatWithNote = function($item) {
|
||||
if (!$item) return null;
|
||||
$formatted = $this->formatItem($item);
|
||||
$formatted['note'] = \App\Models\LegalOpinionNote::select('id', 'note', 'color_code', 'created_at')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('legal_opinion_id', $item->id)
|
||||
->get();
|
||||
return $formatted;
|
||||
};
|
||||
|
||||
$results = array_values(array_filter([
|
||||
$previousItem ? $this->formatItem($previousItem) : null,
|
||||
$this->formatItem($current),
|
||||
$nextItem ? $this->formatItem($nextItem) : null
|
||||
$previousItem ? $formatWithNote($previousItem) : null,
|
||||
$formatWithNote($current),
|
||||
$nextItem ? $formatWithNote($nextItem) : null
|
||||
]));
|
||||
|
||||
return $this->success($results, 'Success', 'Pager Window Details');
|
||||
|
||||
Reference in New Issue
Block a user