feat: chat module

This commit is contained in:
amazuecos
2024-09-23 09:19:45 +02:00
parent bfea4aa67c
commit 766347ad81
28 changed files with 1598 additions and 801 deletions

View File

@ -22,6 +22,15 @@ class ChatDepartments extends Migration
"type" => "VARCHAR",
"constraint" => '255',
],
"description" => [
"type" => "TEXT",
"null" => true,
],
"type" => [
"type" => "ENUM",
'constraint' => ['general', 'presupuesto', 'pedido'],
'default' => 'general',
],
];
public function up()

View File

@ -16,11 +16,25 @@ class ChatsTable extends Migration
"chat_department_id" => [
"type" => "INT",
"unsigned" => true,
"null" => true
],
"pedido_id" => [
"type" => "INT",
"constraint" => 16,
"unsigned" => true,
"null" => true
],
"presupuesto_id" => [
"type" => "INT",
"constraint" => 10,
"unsigned" => true,
"null" => true
],
"factura_id" => [
"type" => "INT",
"constraint" => 10,
"unsigned" => true,
"null" => true
],
@ -31,6 +45,7 @@ class ChatsTable extends Migration
$this->forge->dropTable("chat_mensajes", true);
$this->forge->dropTable("chat_participantes", true);
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql("CURRENT_TIMESTAMP");
$this->forge->addField([
@ -51,6 +66,10 @@ class ChatsTable extends Migration
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('pedido_id', 'pedidos', 'id');
$this->forge->addForeignKey('chat_department_id', 'chat_departments', 'id');
$this->forge->addForeignKey('factura_id', 'facturas', 'id');
$this->forge->addForeignKey('presupuesto_id', 'presupuestos', 'id');
$this->forge->createTable("chats", true);
}

View File

@ -17,14 +17,25 @@ class ChatMessages extends Migration
"unsigned" => true
],
"user_id" => [
"sender_id" => [
"type" => "INT",
"unsigned" => true,
"null" => true,
],
"receiver_id" => [
"type" => "INT",
"unsigned" => true,
"null" => true,
],
"message" => [
"type" => "TEXT",
],
"viewed" => [
"type" => "TEXT",
"type" => "boolean",
"default" => false,
],
];
@ -51,7 +62,8 @@ class ChatMessages extends Migration
],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey(['user_id'], 'users', ['id']);
$this->forge->addForeignKey(['receiver_id'], 'users', ['id']);
$this->forge->addForeignKey(['sender_id'], 'users', ['id']);
$this->forge->addForeignKey(['chat_id'], 'chats', ['id']);
$this->forge->createTable("chat_messages", true);
}

View File

@ -18,7 +18,8 @@ class ChatSeeder extends Seeder
"users" => [
"mbalbaci@safekat.com",
"mari.cano@safekat.com",
"beatriz@safekat.com"
"beatriz@safekat.com",
"imnavajas@coit.es",
],
],
[
@ -26,6 +27,7 @@ class ChatSeeder extends Seeder
"display" => "POD",
"users" => [
"pod@safekat.com",
"imnavajas@coit.es",
],
],
[
@ -33,6 +35,7 @@ class ChatSeeder extends Seeder
"display" => "Maquetación",
"users" => [
"maquetacion@safekat.com",
"imnavajas@coit.es",
],
],
// [
@ -54,6 +57,7 @@ class ChatSeeder extends Seeder
"display" => "Logística",
"users" => [
"logistica@safekat.com",
"imnavajas@coit.es",
],
],
[
@ -61,19 +65,21 @@ class ChatSeeder extends Seeder
"display" => "Administración",
"users" => [
"contabilidad@safekat.com",
"imnavajas@coit.es",
],
],
];
$chatDeparmentModel = model(ChatDeparmentModel::class);
$chatDeparmentUsersModel = model(ChatDeparmentUserModel::class);
$userModel = model(UserModel::class);
foreach ($data as $row) {
$chatDeparmentId = $chatDeparmentModel->insert(["name" => $row["name"], "display" => $row["display"]]);
if (count($row["users"]) > 0) {
foreach ($row["users"] as $mail) {
$user = $userModel->like("username", $mail)->first();
$user = $userModel->like("username", explode("@",$mail)[0])->first();
if ($user) {
echo $user->id."\r\n";
$chatDeparmentUsersModel->insert(['user_id' => $user->id, "chat_department_id" => $chatDeparmentId]);
}
}