Эх сурвалжийг харах

add the user info on dashboard

gdias 1 өдөр өмнө
parent
commit
8ec94d08c6

+ 62 - 0
controllers/UserInfoController.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace Controllers;
+
+use Libs\ResponseLib;
+use Models\UserModel;
+use Psr\Http\Message\ServerRequestInterface;
+use Respect\Validation\Exceptions\ValidationException;
+use Respect\Validation\Validator as val;
+
+class UserInfoController
+{
+    private UserModel $model;
+
+    public function __construct()
+    {
+        $this->model = new UserModel();
+    }
+
+    public function __invoke(ServerRequestInterface $request)
+    {
+        $companyId = (int)($request->getAttribute('api_company_id') ?? 0);
+        if ($companyId <= 0) {
+            return ResponseLib::sendFail('Authenticated company not found', [], 'E_VALIDATE')->withStatus(401);
+        }
+
+        $body = json_decode((string)$request->getBody(), true) ?? [];
+
+        try {
+            val::key('user_id', val::intType()->positive())
+                ->assert($body);
+        } catch (ValidationException $e) {
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400);
+        }
+
+        $userId = (int)$body['user_id'];
+
+        $row = $this->model->getUserInfoById($userId, $companyId);
+        if (!$row) {
+            return ResponseLib::sendFail('User Not Found', [], 'E_DATABASE')->withStatus(204);
+        }
+
+        $data = [
+            'id' => (int)($row['user_id'] ?? 0),
+            'nome' => $row['user_name'] ?? null,
+            'email' => $row['user_email'] ?? null,
+            'telefone' => $row['user_phone'] ?? null,
+            'cpf' => $row['user_cpf'] ?? null,
+            'dataNasc' => isset($row['user_birthdate']) ? (int)$row['user_birthdate'] : null,
+            'kyc' => isset($row['user_kyc']) ? (int)$row['user_kyc'] : null,
+            'roleId' => isset($row['role_id']) ? (int)$row['role_id'] : null,
+            'status' => $row['user_flag'] ?? null,
+            'endereco' => $row['user_address'] ?? null,
+            'cidade' => $row['user_city'] ?? null,
+            'estado' => $row['user_state'] ?? null,
+            'cep' => $row['user_zip'] ?? null,
+            'pais' => $row['user_country'] ?? null,
+        ];
+
+        return ResponseLib::sendOk($data);
+    }
+}

+ 29 - 0
models/UserModel.php

@@ -138,6 +138,35 @@ class UserModel
         return $stmt->fetchAll(\PDO::FETCH_ASSOC);
     }
 
+    public function getUserInfoById(int $userId, int $companyId): ?array
+    {
+        $stmt = $this->pdo->prepare(
+            'SELECT
+                user_id,
+                user_name,
+                user_email,
+                user_phone,
+                user_cpf,
+                user_birthdate,
+                user_kyc,
+                role_id,
+                user_flag,
+                user_address,
+                user_city,
+                user_state,
+                user_zip,
+                user_country
+            FROM "user"
+            WHERE user_id = :user_id AND company_id = :company_id'
+        );
+        $stmt->execute([
+            'user_id' => $userId,
+            'company_id' => $companyId,
+        ]);
+        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
+        return $row ?: null;
+    }
+
     public function deleteUserById(int $userId, int $companyId): bool
     {
         $stmt = $this->pdo->prepare("DELETE FROM \"user\" WHERE user_id = :user_id AND company_id = :company_id");

+ 1 - 0
public/index.php

@@ -45,6 +45,7 @@ $app->post('/verify/jwt', $authJwt,\Controllers\HelloController::class);
 $app->post('/login', \Controllers\LoginController::class);
 $app->post('/register', $authJwt, \Controllers\RegisterController::class);
 $app->post('/user/get', $authJwt, \Controllers\UserGetController::class);
+$app->post('/user/info', $authJwt, \Controllers\UserInfoController::class);
 $app->post('/user/delete', $authJwt, \Controllers\UserDeleteController::class);
 
 // Public endpoint to create company, user, and wallet in a single transaction

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 2 - 0
storage/logs/tshield_response.txt


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно