another fix for export import templates
This commit is contained in:
@@ -28,7 +28,7 @@ public function index()
|
||||
->join('person', 'person.id', '=', 'clients.person_id')
|
||||
->orderBy('person.full_name')
|
||||
->get(['clients.uuid', DB::raw('person.full_name as name')]);
|
||||
|
||||
|
||||
$segments = Segment::query()->orderBy('name')->get(['id', 'name']);
|
||||
$decisions = Decision::query()->orderBy('name')->get(['id', 'name']);
|
||||
$actions = Action::query()->orderBy('name')->get(['id', 'name']);
|
||||
@@ -693,7 +693,7 @@ public function export(ImportTemplate $template)
|
||||
'is_active' => $template->is_active,
|
||||
'reactivate' => $template->reactivate,
|
||||
'meta' => $template->meta,
|
||||
'mappings' => $template->mappings->map(fn($m) => [
|
||||
'mappings' => $template->mappings->map(fn ($m) => [
|
||||
'source_column' => $m->source_column,
|
||||
'entity' => $m->entity,
|
||||
'target_field' => $m->target_field,
|
||||
@@ -704,10 +704,10 @@ public function export(ImportTemplate $template)
|
||||
])->values()->toArray(),
|
||||
];
|
||||
|
||||
$filename = Str::slug($template->name) . '-' . now()->format('Y-m-d') . '.json';
|
||||
$filename = Str::slug($template->name).'-'.now()->format('Y-m-d').'.json';
|
||||
|
||||
return response()->json($data)
|
||||
->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
->header('Content-Disposition', 'attachment; filename="'.$filename.'"');
|
||||
}
|
||||
|
||||
// Import template from JSON file
|
||||
@@ -756,25 +756,25 @@ public function import(Request $request)
|
||||
}
|
||||
|
||||
$clientId = null;
|
||||
if (!empty($data['client_uuid'])) {
|
||||
if (! empty($data['client_uuid'])) {
|
||||
$clientId = Client::where('uuid', $data['client_uuid'])->value('id');
|
||||
}
|
||||
|
||||
// Replace IDs in meta if provided
|
||||
$meta = $json['meta'] ?? [];
|
||||
if (!empty($data['segment_id'])) {
|
||||
if (! empty($data['segment_id'])) {
|
||||
$meta['segment_id'] = $data['segment_id'];
|
||||
}
|
||||
if (!empty($data['decision_id'])) {
|
||||
if (! empty($data['decision_id'])) {
|
||||
$meta['decision_id'] = $data['decision_id'];
|
||||
}
|
||||
if (!empty($data['action_id'])) {
|
||||
if (! empty($data['action_id'])) {
|
||||
$meta['action_id'] = $data['action_id'];
|
||||
}
|
||||
if (!empty($data['activity_action_id'])) {
|
||||
if (! empty($data['activity_action_id'])) {
|
||||
$meta['activity_action_id'] = $data['activity_action_id'];
|
||||
}
|
||||
if (!empty($data['activity_decision_id'])) {
|
||||
if (! empty($data['activity_decision_id'])) {
|
||||
$meta['activity_decision_id'] = $data['activity_decision_id'];
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ class ImportTemplate extends Model
|
||||
'reactivate' => 'boolean',
|
||||
];
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'uuid';
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
||||
Reference in New Issue
Block a user