Files
exchange-2.0/routes/admin_work_flow.php
2024-07-22 01:12:51 +08:00

91 lines
3.4 KiB
PHP

<?php
use App\Classes\Exceptions\RequestValidationException;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Http\Resources\BookingResource;
use App\Models\Booking;
use App\Models\WorkflowTimestamp;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
Route::group(['prefix' => 'admin-work-flow', 'as' => 'admin_work_flow.', 'namespace' => 'AdminWorkFlow'], function () {
Route::get('/fetch-oldest-order', function () {
// currenly, using service id to hardcode fetch
// todo-new: pls confirm need to include 1688 vip orders
$booking = Booking::where('service_id', 4)
->where('status', ApprovalStatus::APPROVED)
// ->latest()
->first();
if (!$booking) return response()->json(['error' => 'No booking found'], 404);
$bank = $booking->bank;
return response()->json([
'passwords' => $bank->holder_name ?? null,
'account_no' => $bank->account_no ?? null,
'pin' => $bank->bank_branch ?? null,
'holder_name' => $bank->holder_name ?? null,
'booking_marking' => $booking->marking ?? null,
]);
})->name('fetch_oldest_order');
Route::post('/add-workflow-timestamp', function (Request $request) {
$validator = Validator::make($request->all(), [
'node' => 'required|string',
'seconds' => 'required|integer',
'userId' => 'required|integer|exists:users,id',
'session_id' => 'required|string',
]);
if ($validator->fails()) throw new RequestValidationException($validator->messages()->first());
$workflowTimestamp = WorkflowTimestamp::create($request->only('node', 'seconds', 'userId', 'session_id'));
return response()->json([
'message' => 'Workflow timestamp created successfully',
'data' => $workflowTimestamp
], 201);
})->name('add_workflow_timestamp');
Route::get('/fetch-pending-approved-po', function () {
// currenly, using service id to hardcode fetch
// todo-new: pls confirm need to include 1688 vip orders
$booking = Booking::with('transactions')
->where('service_id', 4)
->where('status', ApprovalStatus::APPROVED)
->whereHas('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '<', ApprovalStatus::APPROVED))
// ->latest()
->first();
if (!$booking) return response()->json(['error' => 'No booking found'], 404);
return response()->json(new BookingResource($booking));
})->name('fetch_pending_approve_po');
Route::get('/fetch-pending-fill-po', function () {
// currenly, using service id to hardcode fetch
// todo-new: pls confirm need to include 1688 vip orders
$booking = Booking::with('transactions')
->where('service_id', 4)
->where('status', ApprovalStatus::APPROVED)
->whereDoesntHave('transactions', fn ($query) => $query->where('type', TransactionType::PURCHASE_ORDER))
// ->latest()
->first();
if (!$booking) return response()->json(['error' => 'No booking found'], 404);
return response()->json(new BookingResource($booking));
})->name('fetch_pending_fill_po');
});