Fix models database calls and structural updates

This commit is contained in:
Hamza-Ayed
2026-05-21 18:42:33 +03:00
parent 92755472e1
commit 3c695e88fd
5 changed files with 43 additions and 43 deletions

View File

@@ -15,7 +15,7 @@ class Contact extends BaseModel
/**
* Create a new contact with encryption
*/
public function createSecure(array $data)
public static function createSecure(array $data)
{
if (!empty($data['phone'])) {
$data['phone_hash'] = Security::blindIndex($data['phone']);
@@ -31,13 +31,13 @@ class Contact extends BaseModel
$data['notes'] = Security::encrypt($data['notes']);
}
return $this->create($data);
return self::create($data);
}
/**
* Update an existing contact with encryption
*/
public function updateSecure(int $id, array $data)
public static function updateSecure(int $id, array $data)
{
if (isset($data['phone'])) {
$data['phone_hash'] = Security::blindIndex($data['phone']);
@@ -53,35 +53,35 @@ class Contact extends BaseModel
$data['notes'] = Security::encrypt($data['notes']);
}
return $this->update($id, $data);
return self::update($id, $data);
}
/**
* Find a contact by decrypted phone number within a company
*/
public function findByPhone(int $companyId, string $phone)
public static function findByPhone(int $companyId, string $phone)
{
$hash = Security::blindIndex($phone);
$contact = $this->db->query(
"SELECT * FROM {$this->table} WHERE company_id = ? AND phone_hash = ? LIMIT 1",
$contact = \App\Core\Database::selectOne(
"SELECT * FROM " . static::$table . " WHERE company_id = ? AND phone_hash = ? LIMIT 1",
[$companyId, $hash]
)->fetch();
);
return $this->decryptContact($contact);
return self::decryptContact($contact);
}
/**
* Retrieve all contacts for a company
*/
public function findAllByCompany(int $companyId)
public static function findAllByCompany(int $companyId)
{
$contacts = $this->db->query(
"SELECT * FROM {$this->table} WHERE company_id = ? ORDER BY id DESC",
$contacts = \App\Core\Database::select(
"SELECT * FROM " . static::$table . " WHERE company_id = ? ORDER BY id DESC",
[$companyId]
)->fetchAll();
);
foreach ($contacts as &$contact) {
$contact = $this->decryptContact($contact);
$contact = self::decryptContact($contact);
}
return $contacts;
@@ -90,7 +90,7 @@ class Contact extends BaseModel
/**
* Helper to decrypt sensitive fields
*/
private function decryptContact($contact)
private static function decryptContact($contact)
{
if ($contact) {
$contact['phone'] = !empty($contact['phone']) ? Security::decrypt($contact['phone']) : null;