58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Tenant;
|
|
|
|
use App\Http\Controllers\Api\V1\ApiController;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Public lookup used by the customer-web (and later the driver/scanner
|
|
* apps) to validate the LGU code typed before login. No auth required —
|
|
* this answers "does this code exist + is it active" without revealing
|
|
* anything sensitive.
|
|
*/
|
|
class TenantLookupController extends ApiController
|
|
{
|
|
public function lookup(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'code' => ['required', 'string', 'max:64'],
|
|
]);
|
|
|
|
$tenant = Tenant::where('code', strtoupper($data['code']))->first();
|
|
if (! $tenant) {
|
|
return $this->fail('Unknown LGU code', null, 404);
|
|
}
|
|
if ($tenant->status !== Tenant::STATUS_ACTIVE) {
|
|
return $this->fail('LGU is not currently active', null, 403);
|
|
}
|
|
|
|
return $this->ok([
|
|
'id' => $tenant->uuid,
|
|
'code' => $tenant->code,
|
|
'name' => $tenant->name,
|
|
'short_name' => $tenant->short_name,
|
|
'theme_color' => $tenant->theme_color,
|
|
'logo_path' => $tenant->logo_path,
|
|
'timezone' => $tenant->timezone,
|
|
'contact_email' => $tenant->contact_email,
|
|
'contact_phone' => $tenant->contact_phone,
|
|
]);
|
|
}
|
|
|
|
public function index(): JsonResponse
|
|
{
|
|
$tenants = Tenant::where('status', Tenant::STATUS_ACTIVE)->get();
|
|
return $this->ok($tenants->map(fn ($t) => [
|
|
'id' => $t->uuid,
|
|
'code' => $t->code,
|
|
'name' => $t->name,
|
|
'short_name' => $t->short_name,
|
|
'theme_color' => $t->theme_color,
|
|
'logo_path' => $t->logo_path,
|
|
]));
|
|
}
|
|
}
|