Decision now support auto mailing

This commit is contained in:
Simon Pocrnjič
2025-10-12 00:20:03 +02:00
parent 1b615163be
commit 3ab1c05fcc
33 changed files with 1862 additions and 548 deletions
+13 -1
View File
@@ -13,7 +13,14 @@ class Decision extends Model
/** @use HasFactory<\Database\Factories\DecisionFactory> */
use HasFactory;
protected $fillable = ['name', 'color_tag'];
protected $fillable = ['name', 'color_tag', 'auto_mail', 'email_template_id'];
protected function casts(): array
{
return [
'auto_mail' => 'boolean',
];
}
public function actions(): BelongsToMany
{
@@ -29,4 +36,9 @@ public function activities(): HasMany
{
return $this->hasMany(\App\Models\Activity::class);
}
public function emailTemplate(): BelongsTo
{
return $this->belongsTo(\App\Models\EmailTemplate::class, 'email_template_id');
}
}
+2
View File
@@ -18,6 +18,7 @@ class Email extends Model
'is_primary',
'is_active',
'valid',
'receive_auto_mails',
'verified_at',
'preferences',
'meta',
@@ -27,6 +28,7 @@ class Email extends Model
'is_primary' => 'boolean',
'is_active' => 'boolean',
'valid' => 'boolean',
'receive_auto_mails' => 'boolean',
'verified_at' => 'datetime',
'preferences' => 'array',
'meta' => 'array',
+86
View File
@@ -0,0 +1,86 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
enum EmailLogStatus: string
{
case Queued = 'queued';
case Sending = 'sending';
case Sent = 'sent';
case Failed = 'failed';
case Bounced = 'bounced';
case Deferred = 'deferred';
}
class EmailLog extends Model
{
protected $fillable = [
'uuid',
'template_id',
'mail_profile_id',
'user_id',
'message_id',
'correlation_id',
'to_email',
'to_name',
'cc',
'bcc',
'from_email',
'from_name',
'reply_to',
'subject',
'body_html_hash',
'body_text_preview',
'attachments',
'embed_mode',
'status',
'error_code',
'error_message',
'transport',
'headers',
'attempt',
'duration_ms',
'client_id',
'client_case_id',
'contract_id',
'extra_context',
'queued_at',
'started_at',
'sent_at',
'failed_at',
'ip',
];
protected function casts(): array
{
return [
'status' => EmailLogStatus::class,
'cc' => 'array',
'bcc' => 'array',
'to_recipients' => 'array',
'attachments' => 'array',
'headers' => 'array',
'extra_context' => 'array',
'attempt' => 'integer',
'duration_ms' => 'integer',
'queued_at' => 'datetime',
'started_at' => 'datetime',
'sent_at' => 'datetime',
'failed_at' => 'datetime',
];
}
public function template(): BelongsTo
{
return $this->belongsTo(EmailTemplate::class, 'template_id');
}
public function body(): HasOne
{
return $this->hasOne(EmailLogBody::class, 'email_log_id');
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EmailLogBody extends Model
{
protected $fillable = [
'email_log_id',
'body_html',
'body_text',
'inline_css',
];
protected function casts(): array
{
return [
'inline_css' => 'boolean',
];
}
public function log(): BelongsTo
{
return $this->belongsTo(EmailLog::class, 'email_log_id');
}
}