diff --git a/ci4/app/Database/Migrations/2024-09-16-193027_ChatsTable.php b/ci4/app/Database/Migrations/2024-09-14-193027_ChatsTable.php similarity index 83% rename from ci4/app/Database/Migrations/2024-09-16-193027_ChatsTable.php rename to ci4/app/Database/Migrations/2024-09-14-193027_ChatsTable.php index e60249bc..1be8479d 100644 --- a/ci4/app/Database/Migrations/2024-09-16-193027_ChatsTable.php +++ b/ci4/app/Database/Migrations/2024-09-14-193027_ChatsTable.php @@ -13,9 +13,9 @@ class ChatsTable extends Migration "unsigned" => true, "autoincrement" => true ], - "department" => [ - "type" => "VARCHAR", - "constraint" => '255', + "chat_department_id" => [ + "type" => "INT", + "unsigned" => true, ], "pedido_id" => [ "type" => "INT", @@ -50,13 +50,14 @@ class ChatsTable extends Migration ]); $this->forge->addPrimaryKey('id'); $this->forge->addForeignKey('pedido_id', 'pedidos', 'id'); - $this->forge->createTable("chats"); + // $this->forge->addForeignKey('chat_department_id', 'chat_departments', 'id'); + $this->forge->createTable("chats",true); } public function down() { // - $this->forge->dropTable("chats"); + $this->forge->dropTable("chats",true); } } diff --git a/ci4/app/Database/Migrations/2024-09-17-151435_ChatDepartments.php b/ci4/app/Database/Migrations/2024-09-17-151435_ChatDepartments.php index 29f7615b..f537b37e 100644 --- a/ci4/app/Database/Migrations/2024-09-17-151435_ChatDepartments.php +++ b/ci4/app/Database/Migrations/2024-09-17-151435_ChatDepartments.php @@ -41,7 +41,7 @@ class ChatDepartments extends Migration ], ]); - $this->forge->createTable("chat_departments"); + $this->forge->createTable("chat_departments",true); $this->forge->addPrimaryKey('id'); } diff --git a/ci4/app/Database/Migrations/2024-09-17-151450_ChatMessages.php b/ci4/app/Database/Migrations/2024-09-17-151450_ChatMessages.php index f7e8a2ff..14ea7d1c 100644 --- a/ci4/app/Database/Migrations/2024-09-17-151450_ChatMessages.php +++ b/ci4/app/Database/Migrations/2024-09-17-151450_ChatMessages.php @@ -22,6 +22,9 @@ class ChatMessages extends Migration "unsigned" => true, ], + "message" => [ + "type" => "TEXT", + ], ]; @@ -48,7 +51,7 @@ class ChatMessages extends Migration ], ]); - $this->forge->createTable("chat_messages"); + $this->forge->createTable("chat_messages",true); } diff --git a/ci4/app/Database/Migrations/2024-09-17-151500_ChatDepartmentUsers.php b/ci4/app/Database/Migrations/2024-09-17-151500_ChatDepartmentUsers.php index f24f23b9..386af400 100644 --- a/ci4/app/Database/Migrations/2024-09-17-151500_ChatDepartmentUsers.php +++ b/ci4/app/Database/Migrations/2024-09-17-151500_ChatDepartmentUsers.php @@ -38,7 +38,7 @@ class ChatDepartmentUsers extends Migration ], ]); - $this->forge->createTable("chat_department_users"); + $this->forge->createTable("chat_department_users",true); diff --git a/ci4/app/Models/Chat/ChatModel.php b/ci4/app/Models/Chat/ChatModel.php index 06f03f92..25bb5475 100644 --- a/ci4/app/Models/Chat/ChatModel.php +++ b/ci4/app/Models/Chat/ChatModel.php @@ -45,4 +45,19 @@ class ChatModel extends Model 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"); + + } }