feat : migration and chat models

This commit is contained in:
Alvaro Mazuecos Nogales
2024-09-20 11:25:34 +02:00
parent b25abc19d9
commit bfea4aa67c
9 changed files with 158 additions and 59 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace App\Models;
namespace App\Models\Chat;
use CodeIgniter\Model;
@ -12,7 +13,10 @@ class ChatModel extends Model
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [];
protected $allowedFields = [
"pedido_id",
"chat_department_id"
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
@ -44,20 +48,23 @@ class ChatModel extends Model
protected $beforeDelete = [];
protected $afterDelete = [];
public function getChat(int $chat_id)
{
$this->db->table('chats')
->select([
"chats.id as chatId",
"users.id as userId",
"users.email",
"chat_messages.created_at as messageCreatedAt",
"chat_messages.message as messageText",
]
)
->join("users","users.id == chat_messages.user_id","left")
->join("chat_messages","chats.id == chat_messages.chat_id","left");
->select(
[
"chats.id as chatId",
"users.id as userId",
"chats.pedido_id as pedidoId",
"users.email",
"chat_messages.created_at as messageCreatedAt",
"chat_messages.message as messageText",
]
)
->join("users", "users.id == chat_messages.user_id", "left")
->join("chat_deparments", "chat_deparments.id == chats.chat_deparment_id", "left")
->join("chat_messages", "chats.id == chat_messages.chat_id", "left")
->where("chatId", $chat_id)->get()->getResultObject();
}
}