Update: 2026-05-03 23:08:56
This commit is contained in:
40
app/modules_app/tenants/create.php
Normal file
40
app/modules_app/tenants/create.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Create Tenant Endpoint (Super Admin Only)
|
||||
*/
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Core\Validator;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
|
||||
$decoded = AuthMiddleware::check();
|
||||
|
||||
if ($decoded['role'] !== 'super_admin') {
|
||||
json_error('Unauthorized', 403);
|
||||
}
|
||||
|
||||
$data = input();
|
||||
|
||||
$errors = Validator::validate($data, [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email'
|
||||
]);
|
||||
|
||||
if ($errors) {
|
||||
json_error('Validation Failed', 422, $errors);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO tenants (name, email, phone, status, created_at) VALUES (?, ?, ?, 'active', NOW())");
|
||||
$stmt->execute([
|
||||
$data['name'],
|
||||
$data['email'],
|
||||
$data['phone'] ?? null
|
||||
]);
|
||||
|
||||
json_success(null, 'تم إنشاء المكتب بنجاح');
|
||||
} catch (\Exception $e) {
|
||||
json_error('حدث خطأ أثناء حفظ البيانات', 500);
|
||||
}
|
||||
20
app/modules_app/tenants/index.php
Normal file
20
app/modules_app/tenants/index.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Tenants List Endpoint (Super Admin Only)
|
||||
*/
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
|
||||
$decoded = AuthMiddleware::check();
|
||||
|
||||
if ($decoded['role'] !== 'super_admin') {
|
||||
json_error('Unauthorized', 403);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
$stmt = $db->query("SELECT id, name, email, phone, status, created_at FROM tenants ORDER BY created_at DESC");
|
||||
$tenants = $stmt->fetchAll();
|
||||
|
||||
json_success($tenants);
|
||||
Reference in New Issue
Block a user