Decision now support auto mailing
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
|
||||
use App\Models\Action;
|
||||
use App\Models\Decision;
|
||||
use App\Models\EmailTemplate;
|
||||
use App\Models\Segment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class WorkflowController extends Controller
|
||||
@@ -17,6 +17,7 @@ public function index(Request $request)
|
||||
'actions' => Action::query()->with(['decisions', 'segment'])->withCount('activities')->get(),
|
||||
'decisions' => Decision::query()->with('actions')->withCount('activities')->get(),
|
||||
'segments' => Segment::query()->get(),
|
||||
'email_templates' => EmailTemplate::query()->where('active', true)->get(['id', 'name', 'entity_types']),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ public function storeAction(Request $request)
|
||||
'segment_id' => $attributes['segment_id'] ?? null,
|
||||
]);
|
||||
|
||||
if (!empty($decisionIds)) {
|
||||
if (! empty($decisionIds)) {
|
||||
$row->decisions()->sync($decisionIds);
|
||||
}
|
||||
});
|
||||
@@ -59,12 +60,12 @@ public function updateAction(int $id, Request $request)
|
||||
'segment_id' => 'nullable|integer|exists:segments,id',
|
||||
'decisions' => 'nullable|array',
|
||||
'decisions.*.id' => 'required_with:decisions.*|integer|exists:decisions,id',
|
||||
'decisions.*.name' => 'required_with:decisions.*|string|max:50'
|
||||
'decisions.*.name' => 'required_with:decisions.*|string|max:50',
|
||||
]);
|
||||
|
||||
$decisionIds = collect($attributes['decisions'] ?? [])->pluck('id')->toArray();
|
||||
|
||||
\DB::transaction(function() use ($attributes, $decisionIds, $row) {
|
||||
\DB::transaction(function () use ($attributes, $decisionIds, $row) {
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'],
|
||||
@@ -81,6 +82,8 @@ public function storeDecision(Request $request)
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'auto_mail' => 'sometimes|boolean',
|
||||
'email_template_id' => 'nullable|integer|exists:email_templates,id',
|
||||
'actions' => 'nullable|array',
|
||||
'actions.*.id' => 'required_with:actions.*|integer|exists:actions,id',
|
||||
'actions.*.name' => 'required_with:actions.*|string|max:50',
|
||||
@@ -93,9 +96,11 @@ public function storeDecision(Request $request)
|
||||
$row = Decision::create([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'] ?? null,
|
||||
'auto_mail' => (bool) ($attributes['auto_mail'] ?? false),
|
||||
'email_template_id' => $attributes['email_template_id'] ?? null,
|
||||
]);
|
||||
|
||||
if (!empty($actionIds)) {
|
||||
if (! empty($actionIds)) {
|
||||
$row->actions()->sync($actionIds);
|
||||
}
|
||||
});
|
||||
@@ -110,6 +115,8 @@ public function updateDecision(int $id, Request $request)
|
||||
$attributes = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'color_tag' => 'nullable|string|max:25',
|
||||
'auto_mail' => 'sometimes|boolean',
|
||||
'email_template_id' => 'nullable|integer|exists:email_templates,id',
|
||||
'actions' => 'nullable|array',
|
||||
'actions.*.id' => 'required_with:actions.*|integer|exists:actions,id',
|
||||
'actions.*.name' => 'required_with:actions.*|string|max:50',
|
||||
@@ -121,6 +128,8 @@ public function updateDecision(int $id, Request $request)
|
||||
$row->update([
|
||||
'name' => $attributes['name'],
|
||||
'color_tag' => $attributes['color_tag'] ?? null,
|
||||
'auto_mail' => (bool) ($attributes['auto_mail'] ?? false),
|
||||
'email_template_id' => $attributes['email_template_id'] ?? null,
|
||||
]);
|
||||
$row->actions()->sync($actionIds);
|
||||
});
|
||||
@@ -139,6 +148,7 @@ public function destroyAction(int $id)
|
||||
$row->decisions()->detach();
|
||||
$row->delete();
|
||||
});
|
||||
|
||||
return back()->with('success', 'Action deleted successfully!');
|
||||
}
|
||||
|
||||
@@ -153,6 +163,7 @@ public function destroyDecision(int $id)
|
||||
$row->actions()->detach();
|
||||
$row->delete();
|
||||
});
|
||||
|
||||
return back()->with('success', 'Decision deleted successfully!');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user